httpclient

HttpClient异常处理

老子叫甜甜 提交于 2020-01-17 12:22:54
HttpClient 能够抛出两种类型的异常:在 I/O 失败时,如套接字连接超时或被重置的java.io.IOException 异常,还有标志 HTTP 请求失败的信号,如违反 HTTP 协议的HttpException 异常。通常 I/O 错误被认为是非致命的和可以恢复的,而 HTTP 协议错误则被认为是致命的而且是不能自动恢复的。 一、HTTP运输安全 要理解 HTTP 协议并不是对所有类型的应用程序都适合的,这一点很重要。HTTP 是一个简单的面向请求/响应的协议,最初被设计用来支持取回静态或动态生成的内容。它从未向支持事务性操作方向发展。比如,如果成功收到和处理请求,HTTP 服务器将会考虑它的其中一部分是否完成,生成一个响应并发送一个状态码到客户端。如果客户端因为读取超时,请求取消或系统崩溃导致接收响应实体失败时,服务器不会试图回滚事务。如果客户端决定重新这个请求,那么服务器将不可避免地不止一次执行这个相同的事务。在一些情况下,这会导致应用数据损坏或者不一致的应用程序状态。尽管 HTTP 从来都没有被设计来支持事务性处理,但它也能被用作于一个传输协议对关键的任务应用提供被满足的确定状态。要保证 HTTP 传输层的安全,系统必须保证 HTTP 方法在应用层的幂等性。 二、终止请求 在一些情况下,由于目标服务器的高负载或客户端有很多活动的请求,那么 HTTP

httpclient + javascript

前提是你 提交于 2020-01-16 20:58:03
问题 I am using Apache Httpclient and I need to use a Javascript engine to run the script for the page. Similar to a small web browser. Does anybody know a way to integrate javascript with httpclient and send a request back to the original server? 回答1: Checkout http://htmlunit.sourceforge.net/ 来源: https://stackoverflow.com/questions/5587389/httpclient-javascript

httpclient + javascript

喜夏-厌秋 提交于 2020-01-16 20:55:29
问题 I am using Apache Httpclient and I need to use a Javascript engine to run the script for the page. Similar to a small web browser. Does anybody know a way to integrate javascript with httpclient and send a request back to the original server? 回答1: Checkout http://htmlunit.sourceforge.net/ 来源: https://stackoverflow.com/questions/5587389/httpclient-javascript

Get “SocketException: No route to host” instead of the expected “SocketTimeoutException”

风流意气都作罢 提交于 2020-01-16 19:27:52
问题 I use the DefaultHttpClient to fulfill several downlaods. In the case when the enternet is absent I get SocketTimeoutException only for my first download, and for the next downloads I get java.net.SocketException: No route to host .Why does it occur? I use new httpClient for each request. I need to get SocketTimeoutException for each request, because I should keep the timeout delay between downloads attempts. 回答1: Checkout this answers: Android HttpUrlConnection HttpPost receive a

HtmlUnit ValidatorException: PKIX path building failed:

自古美人都是妖i 提交于 2020-01-16 14:31:33
[09:17:36:713] [ERROR] - com.xx.sea.util.HtmlUnitUtil.httpGetResponse(HtmlUnitUtil.java:95) - htmlunit err javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.ssl.Alerts.getSSLException(Alerts.java:192) ~[?:1.8.0_91] at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1949) ~[?:1.8.0_91] at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:302) ~[?:1.8.0_91] at sun.security.ssl.Handshaker.fatalSE

HttpClient stop executing the same HttpGet method in a loop after executing twice

余生长醉 提交于 2020-01-15 03:49:12
问题 Here is my Main Method: public static void main(String[] args) { BasicCookieStore cookieStore = null; HttpResponse httpResponse = null; HttpClient httpClient = HttpClients.createDefault(); while (true) { HttpUriRequest request = new HttpGet("http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/impl/client/HttpClientBuilder.html"); try { httpResponse = httpClient.execute(request); System.out.println(httpResponse.getStatusLine().getStatusCode()); } catch (Exception e

玩个爬虫

孤街醉人 提交于 2020-01-14 19:26:08
想玩个爬虫,爬些数据玩玩,不成想把自己玩“进去”了 想爬这个页面 http://vip.stock.finance.sina.com.cn/quotes_service/view/cn_bill_sum.php?num=100&page=1&sort=totalvolpct&asc=0&volume=200000&type=0&dpc=1 本以为用 HttpClient 直接爬链接,结果发现这个页面中,翻页数据压根就是动态赋值的,根本没有,那我根本无法获知总共有多少页数据,难不成从第一页一直翻页对比,如果与前一页不相同再入库?这不是扯吗,效率太低了; 于是从 HttpClient 追到 webKit ,又从 webKit 追到 JxBrowser ,貌似都不行,有这么邪乎吗? 总是应该有解决方案的吧。 来源: https://www.cnblogs.com/alexgl2008/p/12193421.html

ContentType issue with commons-upload and httpcomponent client

放肆的年华 提交于 2020-01-14 05:23:48
问题 I am trying to develop a Http client which uploads a file with httpcomponents: HttpPost httppost = new HttpPost(myURL); httppost.setHeader("Content-type", "multipart/form-data; boundary=stackoverflow"); httppost.setHeader("Accept", "text/xml"); MultipartEntity reqEntity = new multipartEntity( HttpMultipartMode.BROWSER_COMPATIBLE,"stackoverflow", Charset.forName("UTF-8")); FileBody bin = new FileBody(myFile); reqEntity.addPart("File", bin); httppost.setEntity(reqEntity); HttpResponse response

Custom HttpClient for RemoteConverter of Documents4j

主宰稳场 提交于 2020-01-14 03:34:09
问题 I am using a RemoteConverter from a jBoss web application to a standalone server built as the default server-standalone included into documents4j project. Inside jboss I've got an old version of required libraries httpclient-4.0.1.jar and related httpcore-4.0.1.jar so I'm facing with a lot of ClassDefNotFoundException caused by the different version of the jar loaded by JVM. There is a specific problem with HttpClientConnectionManager object that is not available yet in version To avoid this

# ConfigureAwait常见问题解答

怎甘沉沦 提交于 2020-01-14 00:34:50
原文: https://devblogs.microsoft.com/dotnet/configureawait-faq/ .NET 在七多年前在语言和类库添加了 async/await 。在那个时候,它像野火一样流行,不仅遍及.NET生态系统,而且还可以以多种其他语言和框架进行复制。在利用异步的其他语言构造,提供异步支持的API以及进行async/ await相关的基础架构方面的基本改进方面,.NET也实现了很多改进(特别是.NET Core的性能和支持诊断的改进) 。 但是, async/ await 依旧引起疑问的一个方面是 ConfigureAwait 在这篇文章中,我希望回答其中的许多问题。我希望这篇文章从头到尾都是可读的,并且是可以用作将来参考的常见问题解答(FAQ)列表。 要真正理解 ConfigureAwait ,我们需要提前一点开始… 什么是SynchronizationContext? System.Threading.SynchronizationContext 文档这样描述 SynchronizationContext :它在各种同步模型中提供传输同步上下文的基本功能。这并不是一个显而易懂的描述。 对于99.9%的情况, SynchronizationContext 仅是一种提供虚拟 Post 方法的类型,该方法需要委托以异步方式执行(还有各在