对单个站点的多个 GET 请求(规范)(java)
您好,我正在尝试向单个连接发出 2 个 GET 请求。即
HttpGet get1 = new HttpGet("http://www.google.com/search?q=HelloWorld");
HttpGet get2 = new HttpGet("http://www.google.com/search?q=SecondSearch");
HttpResponse response = null;
response = client.execute(get1);
response = client.execute(get2);
我想从第二次执行中获取主体。显然这失败了,因为它说你必须先释放连接。我需要维护确切的会话 - 例如,如果我导航到第一步是登录的网站,我需要使用相同的 cookie 导航到任何后续页面。
这可能是非常简单的事情,我做错了!
Hi I am trying to make 2 GET requests to a single connection. ie
HttpGet get1 = new HttpGet("http://www.google.com/search?q=HelloWorld");
HttpGet get2 = new HttpGet("http://www.google.com/search?q=SecondSearch");
HttpResponse response = null;
response = client.execute(get1);
response = client.execute(get2);
I would like to get the body from the second execution. Obviously this fails, because it says you must release the connection first. I need to maintain the exact session - for instance, if I navigate to a site where the first step is to login, I need to navigate to any subsequent pages with the same cookie.
It's probably something incredibly simple that I am doing wrong!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用 CookieStore< /a>
在上面的代码中,两个 client2 都会重复使用 client1 请求中的 cookie。
You need to use a CookieStore
In the above code, both client2 will re-use cookies from the client1 request.