如何在多线程操作中使用HttpClient? [英] How to use HttpClient with multithreaded operation?

查看:219
本文介绍了如何在多线程操作中使用HttpClient?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要做一个在某个主机上执行Login POST请求的应用程序,然后导航一些页面,查找并检索一些数据。
因为网站资源受会话保护,所以我必须首先登录网站才能进行一些操作,比如获取或发布一些数据。
我的问题是因为HttpClient不是线程安全的,我怎么能只创建一个HttpClient实例,但是线程可以安全地执行它?
请记住,底层连接必须首先登录才能用于操作。

I've to do an application that performs a Login POST request in a certain host, then navigates some pages, finds and retrieves some data. Becase the website resouce is protected by session, so I have to login the website first before I can do some operation such as get or post some data. My question is because HttpClient is not thread-safe, how can I create only one HttpClient instance but threads can perform on it safely? Remember that the underlying connection must login first before it can be used to operate.

推荐答案

这是一个答案: http://pro-programmers.blogspot.com/2009 /06/apache-httpclient-multi-threads.html

这篇关于如何在多线程操作中使用HttpClient?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆