在Android中将cookie设置为webView
|
检查用户名或密码是否正确时,我从服务器收到“ 0”字样。
当我将ѭ1装入ѭ2时,我希望
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;
}
我用以下方法加载网址:
webView.loadUrl(\"http://a_page.com/getpage.aspx?p=home\");
我想我实际上不是在管理Cookie,也不知道该怎么做。
有什么建议或解决方案吗?
没有找到相关结果
已邀请:
6 个回复
纫合峭
矾醒忻
其中“ 9”的格式与更传统的“ 10” HTTP标头相同,“ 11”是cookie所属的网站。
久纳禾澎
和
网址不同。为
设置cookie与为
设置cookie不同 网址末尾的斜线也可以有所作为。在我的情况下,
起作用,但
不起作用。
正在执行异步操作。因此,如果在设置后立即加载URL,则不能保证cookie已经被写入。为了防止意外和不稳定的行为,请使用CookieManager#setCookie(String url,String value,ValueCallback callback)(link)并在调用回调之后开始加载URL。 我希望我的两分钱能节省一些人的时间,这样您就不必像我一样面对同样的问题。
暑袜眠退
您不能像这样使用它:
擅香
中覆盖
这种方法的一件事:您将不得不重新加载webView。如果有人知道如何解决该问题,请发表评论。
抵浮细