apache-httpclient-4.x

How to POST NON-JSON request using Apache HttpClient?

☆樱花仙子☆ 提交于 2019-12-13 06:19:25
问题 I am to hitting an API which will return string data and as well I want to send data of string type(textfile in a paragraph). 回答1: You can use Apache httpcomponents, with http entities Here is an example for sending a file in your POST request: File file = new File("somefile.txt"); FileEntity entity = new FileEntity(file, ContentType.create("text/plain", "UTF-8")); HttpPost httppost = new HttpPost("http://localhost/action.do"); httppost.setEntity(entity); If you want a text content, you can

JMeter - HTTP Request's Content Encoding field has no effect

爱⌒轻易说出口 提交于 2019-12-13 03:14:34
问题 I tried sending encoding in HTTP Request's Content Encoding field but it doesn't seem to have any effect also in POST request Content encoding to be used (for POST, PUT, PATCH and FILE). This is the character encoding to be used, and is not related to the Content-Encoding HTTP header. I found an answer in archive stating to use HTTP Header Manager instead HTTP Request sampler's Content Encoding field is related to Accept-Charset header. UTF-8, UTF-16, ISO-8859-1, etc. If you want to allow

How to get the body of a 40x response?

我的未来我决定 提交于 2019-12-13 02:37:40
问题 My code is HttpClient client = new DefaultHttpClient(); URI uri = URIUtils.createURI(SCHEME, HOST, PORT, path, formatedParams, null); HttpGet get = new HttpGet(uri); ResponseHandler<String> responseHandler = new BasicResponseHandler(); String responseBody = client.execute(get, responseHandler); When I execute this code and that the response status is 400 , an error is thrown on the last line and I cannot get what should be inside responseBody . If I do the same request via a browser ( Chrome

Apache http client error with json version provided by android

老子叫甜甜 提交于 2019-12-13 02:01:33
问题 I am trying to parse json from url, Apache http client removed from Android API level 23. If I use httpclient.jar files in android studio, it shows error like: "Warning:Dependency org.json:json:20090211 is ignored for debug as it may be conflicting with the internal version provided by Android." dependencies{ compile files('libs/httpclient-4.5.1.jar') compile files('libs/httpcore-4.5.1.jar') } How to resolve this error. Thank you. 回答1: Remove the above two statements from your build.gradle

java httpclient 4.x performance guide to resolve issue

家住魔仙堡 提交于 2019-12-13 01:28:41
问题 There was nice article http://hc.apache.org/httpclient-3.x/performance.html related to http performance, pooling, e.t.c. Can't find the same for the latest 4.x version. Did anyone see it? I met perf issues under heavy load and would like to resolve them. I'm using 4.1 version. Here is profiler output: 26% org.apache.http.impl.client.CloseableHttpClient.execute(multiple parameter matches) :26,107,40 26% org.apache.http.impl.client.CloseableHttpClient.execute(org.apache.http.client.methods

ElasticSearch and Apache HttpAsyncClient

坚强是说给别人听的谎言 提交于 2019-12-12 15:16:27
问题 I'm trying to use ElasticSearch REST API with Java Apache HttpAsyncClient library. I want to use persistent pipelining connection. Here is some test code (output is in comments): @Test public void testEsPipeliningClient() throws IOException, ExecutionException, InterruptedException { testPost(HttpAsyncClients.createDefault()); //201: {"_index":"test_index","_type":"test_type","_id":"AVIHYGnqdqqg_TAHm4ix","_version":1,"_shards":{"total":2,"successful":1,"failed":0},"created":true} testPost

java.lang.NoSuchMethodError: No virtual method execute for HttpClientResponse

跟風遠走 提交于 2019-12-12 14:08:59
问题 When I try to run the app after launching it is showing exception in logcat like this: java.lang.NoSuchMethodError: No virtual method execute(Lorg/apache/http/client/methods/HttpUriRequest;) Lorg/apache/http/client/methods/CloseableHttpResponse; in class Lorg/apache/http/impl/client/DefaultHttpClient; or its super classes (declaration of 'org.apache.http.impl.client.DefaultHttpClient' appears in /system/framework/ext.jar) In class file is getting error after calling execute method.

Unit test timeouts in Apache HttpClient

妖精的绣舞 提交于 2019-12-12 09:51:06
问题 I'm trying to test this method checking that the timeouts are correctly set. public HttpClientBuilder getClientBuilderWithTimeouts(final int connT, final int reqT, final int socketT){ RequestConfig.Builder requestBuilder = RequestConfig.custom(); requestBuilder = requestBuilder.setConnectTimeout(connT); requestBuilder = requestBuilder.setConnectionRequestTimeout(reqT); requestBuilder = requestBuilder.setSocketTimeout(socketT); HttpClientBuilder clientBuilder = HttpClientBuilder.create();

Apache HTTP client 4.3 credentials per request

穿精又带淫゛_ 提交于 2019-12-12 09:35:59
问题 I have been having a look to a digest authentication example at: http://hc.apache.org/httpcomponents-client-4.3.x/examples.html In my scenario the there are several threads issuing HTTP requests and each of them has to be authenticated with their own set of credentials. Additionally, please consider this question is probably very specific for the Apache HTTP client 4.3 onwards, 4.2 handles authentication probably in a different way, although I didn't check it myself. That said, there goes the

Does Apache JMeter support http/2 requests?

。_饼干妹妹 提交于 2019-12-12 07:19:21
问题 Does JMeter 3.2 support HTTP2 ? 回答1: From HTTPClient 4.5 official docs: Standards based, pure Java, implementation of HTTP versions 1.0 and 1.1 SO, you need to wait till HTTP/2 is implemented in HTTPClient libraries and Jmeter implements HTTP2 using the library and create a sampler for the same. 回答2: To sample HTTP/2 requests, you can use a plugin for jmeter, such as this one: https://github.com/syucream/jmeter-http2-plugin From the readme file: Build Netty 5 (Alpha3+) and netty-tcnative for