【发布时间】:2011-04-19 13:13:14
【问题描述】:
在检查用户名或密码是否正确时,我从服务器收到HttpResponse。
当我在webview 中加载url 时,我希望webView 拥有cookie(我通过postData() 得到的答案存储在webView 中。
我希望 webView 获取 cookie 并使用存储在 webview 中的 cookie 加载 url。
我正在收到回复。
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;
}
我用以下方式加载Url:
webView.loadUrl("http://a_page.com/getpage.aspx?p=home");
我想我并没有真正管理 cookie,而且我不知道该怎么做。 有什么建议或解决方案吗?
【问题讨论】:
-
webView CookieManager 的 Android 文档是 developer.android.com/reference/android/webkit/CookieManager
-
这能回答你的问题吗? Android WebView Cookie Problem