1
A
回答
1
CookieManager是你在找什么!
CookieSyncManager.createInstance(context)
创建经理
CookieSyncManager.getInstance().startSync()
在Activity.onResume
(),并在Activity.onPause调用
CookieSyncManager.getInstance().stopSync()
()。
为了获得即时的同步,而不是等待定时器触发,主机可拨打
CookieSyncManager.getInstance().sync()
注意,甚至同步()异步发生,所以不这样做,就像你的活动被关闭。
继承人,你会如何使用它:
// use cookies to remember a logged in status
CookieSyncManager.createInstance(this);
CookieSyncManager.getInstance().startSync();
WebView webview = new WebView(this);
webview.getSettings().setJavaScriptEnabled(true);
setContentView(webview);
webview.loadUrl([MY URL]);
编辑: 如果你想用HttpClient的做到这一点,你需要创建一个HttpContext的。
// Create a local instance of cookie store
CookieStore cookieStore = new BasicCookieStore();
// Create local HTTP context
HttpContext localContext = new BasicHttpContext();
// Bind custom cookie store to the local context
localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
HttpGet httpget = new HttpGet("http://www.google.com/");
System.out.println("executing request " + httpget.getURI());
// Pass local context as a parameter
HttpResponse response = httpclient.execute(httpget, localContext);
相关问题
- 1. 使用来自webview的cookie执行HTTP请求
- 2. 查看HTTP GET请求Cookie
- 3. android http请求忽略cookie
- 4. HTTP请求中的Angular2 Set-Cookie JSESSIONID
- 5. 在HTTP请求/响应中查看Cookie
- 6. $ http不会在请求中发送Cookie
- 7. 如何在http请求中设置cookie?
- 8. 通过HTTPS的HTTP Cookie和Ajax请求
- 9. Android Java保存HTTP请求的Cookie
- 10. http请求的HTTP请求
- 11. Worklight - 拦截HTTP请求以添加Cookie
- 12. HTTP请求何时不带cookie?
- 13. Squid修改HTTP请求并设置Cookie
- 14. HTTP请求Cookie来自哪里?
- 15. Angular2 HTTP请求 - 设置cookie错误
- 16. WKWebView从HTTP请求注入cookie
- 17. Angular:使用http请求设置Cookie
- 18. HTTP Cookie请求头部事件序列
- 19. php http请求
- 20. HttpOnly请求Cookie
- 21. 在JMeter中使用HTTP请求后主体中的Cookie值
- 22. Cookie是否用于在android webview中请求图片来源?
- 23. 使用上下文设置Cookie时,JAXWS中的HTTP请求中未设置Cookie
- 24. 使用Apache的HttpClient如何设置cookie中的HTTP请求
- 25. 传递来自经典ASP页面的http请求中的cookie
- 26. 不能在传出的http请求中禁用cookie在骡3.2
- 27. 在Jmeter中没有验证cookie的一个http请求
- 28. 如何从CURL php中的HTTP请求头获取Cookie内容?
- 29. 如何共享CrawlSpider所拥有的cookie到webview请求(pywebkit)?
- 30. 电子webview取消请求
嗯,我可以将它们添加在DefaultHttpClient? –
我编辑了一个包含使用httppost或httpget客户端的方式 – Jameo
我想你不理解我。我想在我的http客户端中使用我的webview的cookie。对不起,误解 –