apache-httpclient-4.x

HttpClient 4.3.x, fixing deprecated code to use current HttpClient implementations

扶醉桌前 提交于 2019-12-21 03:39:20
问题 I had the following code, which still compiles, but they're all deprecated: SSLSocketFactory sslSocketFactory = new SSLSocketFactory(context, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); ClientConnectionManager clientConnectionManager = base.getConnectionManager(); SchemeRegistry schemeRegistry = clientConnectionManager.getSchemeRegistry(); schemeRegistry.register(new Scheme("https", 443, sslSocketFactory)); return new DefaultHttpClient(clientConnectionManager, base.getParams()); I tried my

NoSuchFieldError INSTANCE at org.apache.http.impl.io.DefaultHttpRequestWriterFactory

[亡魂溺海] 提交于 2019-12-21 03:20:11
问题 java version "1.7.0_71" Gradle 2.1 Hello, UPDATE: The dependencies gradle dependencies | grep httpcore | +--- org.apache.httpcomponents:httpcore:4.3.3 | +--- org.apache.httpcomponents:httpcore:4.3.3 | +--- org.apache.httpcomponents:httpcore:4.3.3 | +--- org.apache.httpcomponents:httpcore:4.3.3 | | | | | +--- org.apache.httpcomponents:httpcore:4.1 -> 4.3.3 | +--- org.apache.httpcomponents:httpcore:4.3.3 | | | | | +--- org.apache.httpcomponents:httpcore:4.1 -> 4.3.3 Does this mean I have 4.1

Creating a UrlEncodedFormEntity from a List of NameValuePairs throws a NullPointerException

…衆ロ難τιáo~ 提交于 2019-12-20 17:23:39
问题 I'm creating a unit test to try out the servlet I just created. @Test public void test() throws ParseException, IOException { HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost("http://localhost:8080/WebService/MakeBaby"); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("father_name", "Foo")); nameValuePairs.add(new BasicNameValuePair("mother_name", "Bar")); post.setEntity(new UrlEncodedFormEntity

how to make Unirest(java) ignore certificate error

房东的猫 提交于 2019-12-20 12:29:25
问题 I am using Unirest (java version) to make GET and POST request.But I encounter a problem when accessing SSL encrypted site , since my program is behind a corporate network and the network admin setup a firewall mapping for me. For example foobar.com is mapped to 56.1.89.12:4444 . But when I make request to the address, I will received the following ssl certificate error: com.mashape.unirest.http.exceptions.UnirestException: javax.net.ssl.SSLException: hostname in certificate didn't match: <56

How can i change charset encoding in HTTP response in Java

落爺英雄遲暮 提交于 2019-12-19 19:55:38
问题 I have to fetch some JSON object from a remote server and for that i am using this function which is working great except that for sometime some weird data is getting fetched which i believe is because it is using ASCII charset to decode. Please find below thw method that i am using public HttpResponse call(String serviceURL,String serviceHost,String namespace,String methodName,String payloadKey, String payloadValue) throws ClientProtocolException,IOException,JSONException { HttpResponse

apache http client org.apache.http.NoHttpResponseException: The target server failed to respond

廉价感情. 提交于 2019-12-19 16:58:53
问题 I am using apache http client to test my WS. I have write a get WS in jersey. URL for this WS is http://localhost:8080/mobilestore/rest/sysgestockmobilews/getinventory?xml=dataString to call this WS using url i have write a method which is as follow public static void getInventory(String input) throws ClientProtocolException, IOException { System.out.println(input); String url = URL + "getinventory"; HttpClient client = new DefaultHttpClient(); List<NameValuePair> nameValuePairs = new

Cancel an HttpClient request

雨燕双飞 提交于 2019-12-19 05:14:44
问题 I am making a simple request for a file using HttpClient from the Apache Commons. Here is my current code: httpclient = new DefaultHttpClient(); httpget = new HttpGet(location); context = new BasicHttpContext(); response = httpclient.execute(httpget, context); entity = response.getEntity(); What would I need to do to cancel this request in the middle of the download? 回答1: You can use httpget.abort() method to abort the request mid way. See example here 来源: https://stackoverflow.com/questions

Apache HTTP - setSocketTimout vs setConnectTimout vs setConnectionRequestTimeout

余生颓废 提交于 2019-12-19 03:15:52
问题 What is the difference between setSocketTimout , setConnectTimout and setConnectionRequestTimeout ? RequestConfig requestConfig = RequestConfig.copy(RequestConfig.DEFAULT) .setSocketTimeout(500) .setConnectTimeout(500) .setConnectionRequestTimeout(500) .build(); 回答1: Connection timeout is the timeout until a connection with the server is established. Socket timeout is the timeout to receive data . The method setConnectionRequestTimeout however is specific for configuring the connection

HTTPClient sends out two requests when using Basic Auth?

主宰稳场 提交于 2019-12-18 13:01:08
问题 I have been using HTTPClient version 4.1.2 to try to access a REST over HTTP API that requires Basic Authentication. Here is client code: DefaultHttpClient httpClient = new DefaultHttpClient(new ThreadSafeClientConnManager()); // Enable HTTP Basic Auth httpClient.getCredentialsProvider().setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(this.username, this.password)); HttpHost proxy = new HttpHost(this.proxyURI.getHost(), this.proxyURI

How can I display all the HTTP Headers when using the DefaultHTTPClient?

ぐ巨炮叔叔 提交于 2019-12-18 12:35:29
问题 When using the DefaultHttpClient() from the Apache Commons HTTP Client, is it possible to show the full request in the console output for debugging purposes? I'm having issues with my application and I feel that the easiest way to debug it it would be to inspect all data sent by the DefaultHTTPClient . 回答1: You can get all headers like this: Enumeration headerNames = request.getHeaderNames(); while(headerNames.hasMoreElements()) { String headerName = (String)headerNames.nextElement(); out