apache-httpclient-4.x

Multi-part POST with file and string in HTTPClient 4.1

随声附和 提交于 2019-12-04 06:42:25
I need to create Multi-part POST request containing fields: update[image_title] = String update[image] = image-data itself . As you can see both are in associative array called "update". How could I do it with HTTPClient 4.1, because I found only examples for 3.x line of this library. Thank you in advance. Probably too late but might help someone. I had the exact same issue. Assuming that you have a file object which has necessary information about the image HttpPost post = new HttpPost(YOUR_URL); MultipartEntity entity = new MultipartEntity(); ByteArrayBody body = new ByteArrayBody(file

Java : HttpClient 4.1.2 : ConnectionTimeout, SocketTimeout values set are not effective

你离开我真会死。 提交于 2019-12-04 06:18:24
I am using HttpClient 4.1.2. Setting ConnectionTimeout and SocketTimeout to a value is never effective. code : Long startTime = null; DefaultHttpClient httpClient = new DefaultHttpClient(); HttpParams params = httpClient.getParams(); HttpConnectionParams.setConnectionTimeout(params, 30); HttpConnectionParams.setSoTimeout(params, 60); HttpGet httpget = new HttpGet("http://localhost:8080/Test/ScteServer"); try { startTime = System.currentTimeMillis(); HttpResponse response = httpClient.execute(httpget); } catch(SocketTimeoutException se) { Long endTime = System.currentTimeMillis(); System.out

Java HttpClient - Post with file through Proxy

大兔子大兔子 提交于 2019-12-04 05:09:24
问题 I try calling an external website from my webapplication with a proxy. Furthermore and need to execute a POST Request at this external website. I'm using: tomcat7, org.apache.httpcomponents 4.3.4, spring. Following, without proxy, works and I get a response status '200'; // uri = "https://punkte.eiv-fobi.de/upload/upload.do" private HttpStatus sendPost(URI uri, File file) throws ClientProtocolException, IOException { HttpClient httpClient = HttpClientBuilder.create().build(); HttpPost

Programmatically provide NiFi InvokeHTTP different certificates

北城余情 提交于 2019-12-04 02:09:32
问题 I have a requirement in Nifi where I have cycle through different HTTP S REST Endpoints and provide different certificates for some endpoints and different username / password for some other endpoints. I used InvokeHTTP processor to send the requests, although URL takes an expression language, I cannot setup SSLContextService with an expression. Alternatively, I thought on using ExecuteScript to call those Endpoints, however as listed here in StackOverflow post; I still don't know how to

HttpClient get status code

大城市里の小女人 提交于 2019-12-03 23:11:56
问题 Using Apache HttpClient 4.1.3 and trying to get the status code from an HttpGet : HttpClient client = new DefaultHttpClient(); HttpGet response = new HttpGet("http://www.example.com"); ResponseHandler<String> handler = new BasicResponseHandler(); String body = client.execute(response, handler); How do I extract the status code (202, 404, etc.) from the body ? Or, if there's another way to do this in 4.1.3, what is it? Also, I assume a perfect/good HTTP response is an HttpStatus.SC_ACCEPTED

Apache HttpClient in Android extremely slow downloading attachment

别来无恙 提交于 2019-12-03 21:53:02
I am trying to download a zip file using HttpCLient 4 and it is going at around .5 (kilobytes/kilobits)? per minute. The file is less than a MB large, and the download will probably take an hour! Am I doing something wrong? How else should I do this? Here is my current implementation: @Override protected Uri doInBackground(String... params) { publishProgress("Downloading..."); try { HttpPost searchPOST = new HttpPost("http://www.somesite.com/" + searchResult.getURLSuffix()); List<NameValuePair> formparams = new ArrayList<NameValuePair>(); //added parameters here... UrlEncodedFormEntity

How to update the settings of an HttpClient in httpclient 4.3+?

落爺英雄遲暮 提交于 2019-12-03 21:38:27
In httpclient 4.3, if you respect all the deprecations, you must build and configure your HttpClient using an HttpClientBuilder (documentation here ). The methods are explicit, they seem easy to use, and HttpClient 's interface is clear. But maybe a tad too much. In my own case, I have to inherit Spring's HttpComponentsHttpInvokerRequestExecutor (documentation here ). As a consequence, I can easily get the HttpClient , but all I know about this object is that it implements the interface. Since the client is already built, and I do not know anything about its implementation, I cannot access

Handshake fail on Lollipop

最后都变了- 提交于 2019-12-03 21:26:44
I'm trying to do a HTTP POST but I get two different errors: javax.net.ssl.SSLHandshakeException: Handshake failed net.ssl.SSLPeerUnverifiedException: No peer certificate I fixed the No peer certificate error through a workaround as specified here: https://stackoverflow.com/a/4837230/4254419 but while that fixes the error, it throws a new error instead, which is Handshake failed I know it's not safe and I don't care, it's not for production so I care less about security. Is there a fix for this issue? I had the same problem. I found a link https://code.google.com/p/android/issues/detail?id

Java, Apache HttpClient, TLSv1.2 & OpenJDK 7

ぐ巨炮叔叔 提交于 2019-12-03 20:23:58
We have a small group of Tomcat servers running OpenJDK v1.7.0_111. We have plans to upgrade them and migrate them this summer but we've found that a client API we interact with is moving to require TLSv1.2 in the near term. My ultimate desire is to find a configuration change to allow for this. The application hosted there creates it's SSL context in a pretty straight forward way: SSLContext sslContext = SSLContexts.createDefault() SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext); SSLContexts is from Apache's httpclient library (version 4.4.1) and is also pretty

Generating HttpRequest from specific IP in Java

别来无恙 提交于 2019-12-03 20:15:24
I am using Apache HttpClient for generating Post request and submitting the data. Since remote application relays on IP address of the user that's submitting the data, I want to send post request for user specified IP address. How do I configure this? public static void loginUser(String username, String password, String ip) throws Exception{ try { HttpClient client = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://login.myapp.com/"); // Request parameters and other properties. List<NameValuePair> params = new ArrayList<NameValuePair>(2); params.add(new BasicNameValuePair(