apache-httpclient-4.x

Google Documents List API file upload 400 response

只谈情不闲聊 提交于 2019-12-12 05:37:20
问题 I am writing my own implementation of the Google Drive client for the Android and I am using the docs list api. Recently I've encountered a following problem: At first I was using the HttpURLConnection to upload the file but it seems like it writes the data to the socket after a call to getResponseCose(), not when I am writing to the connection's OutputStream, which is a must for me. Then I've switched to the Apache HttpClient but I'm still getting a 400 response, not sure why. Maybe you will

Decompress gzip json response to string in Android

百般思念 提交于 2019-12-12 04:44:58
问题 This is my code: try { HttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url); httpPost.setEntity(new StringEntity(strJson, "UTF-8")); httpPost.setHeader("api_key", "<TSssssssssssssaaa7>"); httpPost.setHeader("Content-Type", "application/json"); httpPost.setHeader("Accept-Encoding", "gzip"); response = httpClient.execute(httpPost); resp=EntityUtils.toString(response.getEntity(), "UTF-8"); Log.w("QueingSystem", strJson); Log.w("QueingSystem", EntityUtils

Pull information from Json array

╄→尐↘猪︶ㄣ 提交于 2019-12-12 04:38:35
问题 All, I have following JSON response after request get list of users. I want to pull just only one user's id using userName. For example if i want id of userName Test1, how to do that? Any help will be appreciated. { "displayLength": "4", "iTotal": "20", "users": [ { "id": "2", "userName": "Test1", "Group": { id:1 name:"Test-Admin" } }, { "id": "17", "userName": "Test2", "Group": { id:1 name:"Test-Admin" } }, { "id": "32", "userName": "Test3", "Group": { id:1 name:"Test-Admin" } }, { "id": "35

In apache http client, how to keep the Content-Type in a StringBody as empty or null?

Deadly 提交于 2019-12-12 03:48:14
问题 We have a restful API (which we cannot change) where if the Content-Type value for a part is null, we have a specific processing. Until httpclient3.x, we could do a the following and set the content type as null. StringPart sp = new StringPart("name, "value") sp.setContentType(null); Now, we have moved to http components (httpclient4.x jar) and I realised that we need to pass an instance of ContentBody (StringBody to be precise). Found the following 2 ways of doing the same in the new version

PropertyAccessException in Apache camel Spring Ws Configuration

狂风中的少年 提交于 2019-12-12 02:52:04
问题 I want to configure Spring-ws Connection Manager to use PoolingHttpClientConnectionManager . here is my configuration camel-context.xml <camel-context> <route> <from uri="direct:sampleCall"/> <to uri="bean:sampleCommand"/> <to uri="spring-ws:http://{{sample.uri}}?timeout={{sample.timeout}}&messageSender=#messageSender&soapAction=urn:MidwareWebServiceIntf-MidwareWebService#sampleCommand"/> <to uri="bean:xmlProcessor"/> <to uri="bean:validateResponse"/> </route> <route> <from uri="direct

Should I set the Content-Type header for a MultipartEntity?

 ̄綄美尐妖づ 提交于 2019-12-12 02:45:16
问题 I've got a small piece of code which submits an XML entity along with binary data in the same POST. I'm using the httpclient and httpmime for this. I'm not quite sure if I should set the Content-Type header for this request. After all, the Content-Type is both application/xml and application/octet-stream . What's the correct usage for this? post = new HttpPost(uri); post.setHeader("Authorization", auth); // Should I set Content-Type at all? post.setHeader("Content-Type", mimeType + ";charset

Download files from different domains with one connection

强颜欢笑 提交于 2019-12-12 01:17:09
问题 Well this question may sounds a little crazy but I just want to save time and engergy. To open a connection needs time and engergy on a mobile device so I want to reuse open connections if possible. It can happen that I'll need to download files from example.com and example.net . Both sites are hosted on the same server/ip so it should be possible to get documents from both documents with just one connection. DefaultHttpClient client = new DefaultHttpClient(); HttpGet get = new HttpGet("http:

HttpClient post with Content-Disposition

痴心易碎 提交于 2019-12-12 00:27:00
问题 Good evening. Usually I'm working with post request like that name1=value1&name2=value2 and my code is List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("name1", "value1")); httppost.setEntity(new UrlEncodedFormEntity("name2","value2"); But now I have the post like that -----------------------------17911109517875 Content-Disposition: form-data; name="PERSON*1[F*2][2664]" value1 -----------------------------17911109517875 Content

How can I download a file using a simple HttpClient example?

被刻印的时光 ゝ 提交于 2019-12-11 23:22:29
问题 I'm new with Java and HttpClient, and I'm trying to do a simple download from a Dropbox file but I just get the following exception: Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory at org.apache.http.impl.client.AbstractHttpClient.<init>(AbstractHttpClient.java:187) at org.apache.http.impl.client.DefaultHttpClient.<init>(DefaultHttpClient.java:146) at downlaodtest.DownlaodTest.main(DownlaodTest.java:23) Caused by: java.lang

Unable to login to WSJ using HtmlUnit/HttpClient

余生长醉 提交于 2019-12-11 19:19:36
问题 I am a paid member of WSJ. I want to login to WSJ using HtmlUnit, but am unable to do so. Following is my code : WebClient webClient = new WebClient(BrowserVersion.FIREFOX_24); webClient.getOptions().setJavaScriptEnabled(true); webClient.getOptions().setCssEnabled(false); webClient.getOptions().setRedirectEnabled(true); webClient.getOptions().setThrowExceptionOnScriptError(false); webClient.setAjaxController(new NicelyResynchronizingAjaxController()); webClient.getCookieManager()