Logging in via HttpPost to a website via an application

自闭症网瘾萝莉.ら 提交于 2019-12-04 15:35:35
Andrzej Gis

My guess is that your application doesn't handle cookies right. Take a look at this question, it may help.

WebView and Cookies on Android

EDIT

In your code you seem to pass only the html retrieved from request to the WebView. Cookies seem to get lost somewhere. I'd suggest you another approach.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    WebView webv = (WebView)findViewById(R.id.MainActivity_webview);         
    webv.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
    });

    String postData = FIELD_NAME_LOGIN + "=" + LOGIN +
            "&" + FIELD_NAME_PASSWD + "=" + PASSWD;

    // this line logs you in and you stay logged in
    // I suppose it works this way because in this case WebView handles cookies itself
    webv.postUrl(URL, EncodingUtils.getBytes(postData, "utf-8"));
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!