apache-httpclient-4.x

Write in body request with HttpClient

妖精的绣舞 提交于 2019-11-27 17:35:15
I want to write the body of a request with XML content-type but I don't know how with HttpClient Object ( http://hc.apache.org/httpclient-3.x/apidocs/index.html ) DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost httpRequest = new HttpPost(this.url); httpRequest.setHeader("Content-Type", "application/xml"); And I don't know how to continue to write the body with my XML ... If your xml is written by java.lang.String you can just using HttpClient in this way public void post() throws Exception{ HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost("http://www

How to use DefaultHttpClient in Android? [closed]

筅森魡賤 提交于 2019-11-27 16:35:07
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . How to use DefaultHttpClient in Android? 回答1: I suggest reading the tutorials provided with android-api. Here is some random example which uses DefaultHttpClient, found by simple text-search in examples-folder.

Android Rest Client

老子叫甜甜 提交于 2019-11-27 15:18:56
问题 I found so many samples for requesting a REST API, but all together are confusing, can some one please explain me a way to use http requests. My Requirement is, I want to get data from a REST API by providing username, pwd and a key. What I have Used was, HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost("REST API url"); post.setHeader("Content-type", "application/json"); JSONObject obj = new JSONObject(); obj.put("username", "un"); obj.put("pwd", "password"); obj.put(

Basic Authentication with RestTemplate (3.1)

◇◆丶佛笑我妖孽 提交于 2019-11-27 15:10:56
问题 I am trying to reproduce the following curl command using Java: curl -v -u user:pass http://myapp.com/api This command returns some JSON data. My buggy Java implementation is as follows: @Test public void callTest() { RestTemplate restTemplate = createRestTemplate("user", "pass"); URI uri = new URI("http://myapp.com/api"); String res = restTemplate.getForObject(uri, String.class); } private static RestTemplate createRestTemplate(String username, String password) { UsernamePasswordCredentials

Apache 4.1 HttpClient POST and GET [closed]

邮差的信 提交于 2019-11-27 14:33:51
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed last year . Can anyone provide an example of how I could use GET and POST (Apache 4.1 HttpClient)? Because most of the example that I found are using 3.x 来源: https://stackoverflow.com/questions/3375940/apache-4-1-httpclient-post-and-get

Receiving Multipart Response on client side (ClosableHttpResponse)

三世轮回 提交于 2019-11-27 14:32:35
I have a java controller which have to send me some text data and different byte arrays. So I am building n multipart request and writing it to stream from HttpServletResponse. Now my problem is how to parse the response at client side and extract the multiple parts. SERVER CODE SNIPPET:- MultipartEntityBuilder builder = MultipartEntityBuilder.create(); // Prepare payload builder.addBinaryBody("document1", file); builder.addBinaryBody("document2", file2); builder.addPart("stringData", new StringBody(jsonData, ContentType.TEXT_PLAIN)); // Set to request body HttpEntity entity = builder.build();

HttpClient Post with progress and MultipartEntityBuilder

懵懂的女人 提交于 2019-11-27 14:31:14
I try to implement an progress while uploading an file with HttpClient 4.3.3 and MultipartEntityBuilder So actually i execute a post request with the following code HttpClientBuilder builder = HttpClientBuilder.create(); HttpClient httpClient = builder.build(); HttpPost httpPost = new HttpPost(uploadUrl); MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create(); entityBuilder.addPart("filea", new FileBody(filea)); entityBuilder.addPart("fileb", new FileBody(fileb)); final HttpEntity entity = entityBuilder.build(); httpPost.setEntity(entity); HttpResponse response = httpClient

How to get HttpClient returning status code and response body?

依然范特西╮ 提交于 2019-11-27 14:18:03
问题 I am trying to get Apache HttpClient to fire an HTTP request, and then display the HTTP response code (200, 404, 500, etc.) as well as the HTTP response body (text string). It is important to note that I am using v4.2.2 because most HttpClient examples out there are from v.3.x.x and the API changed greatly from version 3 to version 4. Unfortunately I've only been able to get HttpClient returning the status code or the response body (but not both). Here's what I have: // Getting the status

Android: Scheme 'http' not registered on ICS 4.0.4 w/ proxy

北城余情 提交于 2019-11-27 14:08:51
问题 I'm using HttpClient for HTTPS requests, which has worked fine up until now. After upgrading to ICS, some users are reporting problems connecting on 3G connections. EDIT: Most of them seem to be using a proxy, and I can reproduce this locally with a T-Mobile SIM using their proxy. The logs have this stack trace: java.lang.IllegalStateException: Scheme 'http' not registered. org.apache.http.conn.scheme.SchemeRegistry.getScheme(SchemeRegistry.java:80) org.apache.http.impl.conn

http connection timeout issues

China☆狼群 提交于 2019-11-27 11:42:08
问题 I'm running into an issue when i try to use the HttpClient connecting to a url. The http connection is taking a longer time to timeout, even after i set a connection timeoout. int timeoutConnection = 5000; HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); int timeoutSocket = 5000; HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); It works perfect most of the time. However, every once in while, the http connection runs for ever and ignore the