问题描述
我要做一个在某个主机上执行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.
推荐答案
这是一个答案:
这篇关于如何在多线程操作中使用HttpClient?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!