设置一个cookie在Android的一个web视图 [英] Set a cookie to a webView in Android

查看:102
本文介绍了设置一个cookie在Android的一个web视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我检查时,如果用户名和密码是正确的获得一个的Htt presponse 从服务器。 当我加载网​​址的WebView 我要的 web视图有饼干(我与 POSTDATA()存储在 web视图。 我想web视图皮卡饼干和加载的URL与存储在web视图该Cookie。

I'm getting a HttpResponse from a server when checking if a username or password is correct. When I load the url in a webview I want the webView to have the cookie (the answer I get with postData() stored in the webView. I want the webView to pickup the cookie and load the url with that cookie stored in the webview.

我收到过的响应。

public HttpResponse postData() {
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("https://example.com/login.aspx");

    try {
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("txtUsername", "user"));
        nameValuePairs.add(new BasicNameValuePair("txtPassword", "123"));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        HttpResponse response = httpclient.execute(httppost);
        String responseAsText = EntityUtils.toString(response.getEntity());
        Log.v(TAG , "Response from req: " + responseAsText);
        return responseAsText;

    } catch (ClientProtocolException e) {

    } catch (IOException e) {

    }
    return null;
}

和我使用loadURL有:

And I loadUrl with:

webView.loadUrl("http://a_page.com/getpage.aspx?p=home");

我想我没有真正管理一个cookie,我不知道怎么做。 任何建议或解决方案?

I guess I'm not really managing a cookie and I have no idea how to do so. Any suggestions or solutions?

推荐答案

您可能会想看看这个解决方案:的的Andr​​oid的WebView曲奇问题

You'll probably want to take a look at this solution: Android WebView Cookie Problem

这篇关于设置一个cookie在Android的一个web视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆