当检查用户名或密码是否正确时,我从服务器获取HttpResponse.
当我在网页视图中加载网址时,我希望webView拥有cookie(使用postData()存储在webView中的答案).
我想要webview来取代cookie,并加载该网址存储在webview中的URL.
当我在网页视图中加载网址时,我希望webView拥有cookie(使用postData()存储在webView中的答案).
我想要webview来取代cookie,并加载该网址存储在webview中的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; }
和我loadUrl与:
webView.loadUrl("http://a_page.com/getpage.aspx?p=home");
我想我不是真的管理一个cookie,我不知道该怎么做.
任何建议或解决方案?
解决方法
你可能想看看这个解决方案:
Android WebView Cookie Problem