apache-httpclient-4.x

How to solve org.apache.http.NoHttpResponseException

萝らか妹 提交于 2019-12-09 07:03:48
问题 I'm using apache httpclient 4.4 to do https requests, and I can constantly to see org.apache.http.NoHttpResponseException . Here's my code to create the httpclient. TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { @Override public java.security.cert.X509Certificate[] getAcceptedIssuers() { return null; } @Override public void checkClientTrusted(X509Certificate[] certs, String authType) { } @Override public void checkServerTrusted(X509Certificate[] certs, String

Digest auth with Java & Apache client : Always 401 Unauthorized

99封情书 提交于 2019-12-09 06:46:32
问题 I'm trying to implement digest auth with an HTTP client, but this does not work at the moment. Can someone check if this code is correct? For testing purpose I use http://httpbin.org/, but all I get is HTTP/1.1 401 Unauthorized . Here is the example code: private static void doDigestAuth() throws ClientProtocolException, IOException, AuthenticationException, MalformedChallengeException { HttpHost target = new HttpHost("httpbin.org", 80, "http"); CredentialsProvider credsProvider = new

Mocking HttpClient.execute issues: Mockito

我与影子孤独终老i 提交于 2019-12-08 14:00:17
问题 I am trying to test this method. @Override public JSON connectResource() throws IOException { //get the location and credentials for the certificates System.setProperty("javax.net.ssl.trustStore", "C:/Program Files/Java/jdk1.7.0_40/jre/lib/security/cacerts"); System.setProperty("javax.net.ssl.trustStorePassword", "changeit"); HttpRequest httpRequest = new HttpGet(url); System.out.println("hello"); httpRequest.addHeader("Accept", "application/json"); HttpResponse response = httpClient.execute(

Reading and terminating stream in HttpClient 4

你。 提交于 2019-12-08 09:06:59
问题 I'm reading large documents from which I only need top 5%, can I do the following with HttpClient 4? Request the page (get or post) Read response as a stream Feed it into SAX-based HTML parser "on the fly" When certain HTML tag is detected - terminate the stream Please note that HttpClient v. 4 is required - I cannot use v. 3 回答1: Thanks to Ken from HttpClient mail list here's the answer Use the HttpEntity#getContent() method, which returns an java.io.InputStream, and pass that to your SAX

How to set TCP keep Alive in java from httpclient

那年仲夏 提交于 2019-12-08 08:21:40
问题 My java application which resides in AWS private subnet connects to an http server via AWS Nat gateway. I am calling a POST request via httpclient to the HTTP server. That request will take more than 10 minutes to complete. I have configured a socket time out and connection timeout of 1 hour as this this a background task . But the intermediate AWS NAT gateway will send back a RST packet after 300 secs [5 mins] and cause the connection to get resetted , there is no way i can increase the NAT

Certificate chain different between HTTPSURLconnection and Apache (System) DefaultHttpClient

半腔热情 提交于 2019-12-08 05:26:46
问题 I am facing a weird issue wrto Apache HTTPS client. I am trying to connect to an external HTTPS website which has basic authentication turned on (SSL server authenticaion only). Here is the summary of my tests and conclusions. Use a either of Chrome/Firefox/IE to connect to the website -> success Use javax.net.ssl.HttpsURLConnection -> success Use either of DefaultHttpClient or SystemDefaultHttpClient -> failure I tried to debug by enabling "javax.net.debug" to "ssl". I noticed that both the

How to post array parameters with HttpComponents

假如想象 提交于 2019-12-08 04:32:20
问题 I want to perform this command with Apache http-components (4.1.2) curl --data "strings[]=testOne&string-keys[]=test.one&strings[]=testTwo&string-keys[]=test.two&project=Test" https://api.foo.com/1/string/input-bulk The target api need strings and string-keys parameters as array , which mean repeating strings[] and string-keys[] for each parameter. This curl command works fine but with Http-component, while I got exactly the same parameters. Maybe I'm doing something wrong. List<NameValuePair

Configuring Apache HttpClient to access service through proxy/load-balancer (overriding Host header)

≯℡__Kan透↙ 提交于 2019-12-07 12:55:52
问题 I am having a problem getting the Apache HttpClient to connect to a service external to my virtualised development environment. To access the internet (e.g. api.twitter.com) I need to call a local URL (e.g. api.twitter.com.dev.mycompany.net), which then forwards the request to real host. The problem is, that to whatever request I send, I get a 404 Not Found response. I have tried debugging it using wget, and it appears the problem is, that the destination server identifies the desired

HttpRoutePlanner - How does it work with an HTTPS Proxy

自闭症网瘾萝莉.ら 提交于 2019-12-07 11:33:30
问题 I have an HTTPS proxy set up so that HTTP clients can send plain HTTP requests securely to the proxy. For example, a client can send an encrypted HTTP GET request to the proxy, which will remove the encryption and send the plain HTTP GET request to the end-site. I learned that this is not a common set up and only Google Chrome has in-built features to support such a scenario. (Info here - http://wiki.squid-cache.org/Features/HTTPS#Encrypted_browser-Squid_connection). I have made Google Chrome

How can I get a custom Content-Disposition line using Apache httpclient?

笑着哭i 提交于 2019-12-07 06:15:29
问题 I am using the answer here to try to make a POST request with a data upload, but I have unusual requirements from the server-side. The server is a PHP script which requires a filename on the Content-Disposition line, because it is expecting a file upload. Content-Disposition: form-data; name="file"; filename="-" However, on the client side, I would like to post an in-memory buffer (in this case a String) instead of a file, but have the server process it as though it were a file upload.