apache-commons-httpclient

HTTP post with image and data

末鹿安然 提交于 2019-12-13 05:58:23
问题 I am using apache HTTP Client for callin rest endpoints. I want to call a POST request with image and some more form data as parameters. I can do them separately with to requests like first for the form data and the other for the image alone. Is there any possible solution so that i can do it with one request. Below is the api call http://<url>?hint=hi&def=ready&image=<imagefile> 回答1: Use Multipart Request. Commons Apache File Upload API has very good API for the same. Apache Commons

Can I get cached images using HttpClient?

情到浓时终转凉″ 提交于 2019-12-13 05:15:32
问题 Is it possible to load login page once, using HttpClient, and get image file of img element from cache, not from src link, without reload? It is important because I need to save captcha for just loaded page, if I try load it from src link, it will be another captcha. I tried: DefaultHttpClient httpclient = new DefaultHttpClient(); HttpGet httpget = new HttpGet("http://www.mysite/login.jsp"); HttpResponse response = httpclient.execute(httpget); HttpEntity entity = response.getEntity();

Converting from HttpClient 3 to 4

时光怂恿深爱的人放手 提交于 2019-12-12 08:29:30
问题 I've managed to make changes to everything but the following: HttpClient client; HttpPost method; client = new DefaultHttpClient(); method = new HttpPost(url); InputStream rstream; try { rstream = method.getResponseBodyAsStream(); } catch (IOException e) { return BadSpot(e.getMessage()); } What I'm not sure of is what I should replace getResponseBodyAsStream() with. 回答1: InputStream rstream; try { HttpResponse response = client.execute(HttpHost, method); rstream = response.getEntity()

Read multipart/mixed response in Java/Groovy

╄→гoц情女王★ 提交于 2019-12-12 07:23:02
问题 I am getting a "multipart/mixed" response to an http request that I need to parse. One part of the response is a pdf file which I need to save to disk. Is there any library that will do this for me? 回答1: Here is what I did in groovy. Needed java mail library: //... get reader from response, can use response.success callback in http.request ByteArrayDataSource ds = new ByteArrayDataSource(new ReaderInputStream(reader), "multipart/mixed"); MimeMultipart multipart = new MimeMultipart(ds);

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

How to use Apache FileUppload and HttpClient?

心已入冬 提交于 2019-12-11 18:34:24
问题 I am writing some code to send a log file via http to a server if a JAWS app fails. To test this I have setup a servlet that receives and processes the request. My Client code is as from the Apache HttpClient 4.2 examples { HttpClient httpclient = new DefaultHttpClient(); try { HttpPost httppost = new HttpPost("http://localhost:8080/testServer/testserv/a"); FileBody bin = new FileBody(new File("XXXs")); StringBody comment = new StringBody("A binary file of some kind"); MultipartEntity

How to re-send or retain a session cookie

微笑、不失礼 提交于 2019-12-11 15:32:41
问题 I have been trying to handle a redirect (302) in java code and I am finally been able to do it. But I am running into a problem. Which is, once the redirect opens a page, clicking any link on the page sends me back to the login page. So I have to write my own redirect implementation: private HttpMethod loadHttp302Request(HttpMethod method, HttpClient client, int status, String urlString) throws HttpException, IOException { if (status != 302) return null; String[] url = urlString.split("/");

Dynamically configuring Apache Http client

那年仲夏 提交于 2019-12-11 06:55:42
问题 I am creating a module that uses http://hc.apache.org/httpcomponents-client-4.2.x/index.html to make HTTP requests to external services. This module is going to be used by application. The application configures different aspect of the module by XML based config file. and I want to specify the logging level to be used for http communication in that XML file. The module will read that config file, and configure apache HTTP client with that logging level. I could not find any way how

Apache HttpClient - post request to ETools.ch with utf-8 chars in the query

浪子不回头ぞ 提交于 2019-12-11 04:23:01
问题 The code works fine if the query does not contain any utf-8 chars. As soon as there is one utf-8 char then ETools provides results I do not expect. For example for "trees" I get correct result and for "bäume" (german word for trees) I get strange results. It looks like that ETools receives the query as "b%C3%A4ume" and looks for exact that query with exact those chars and not for "bäume" . I think the problem may be solved if I set some header parameters but I dont know what parameters are

HttpClient: disabling chunked encoding

浪尽此生 提交于 2019-12-11 02:40:27
问题 I am using the Apache Commons HttpClient along with Restlet to call a restful web service. Unfortunately, my server (based on Ruby on Rails) does not like the Transfer-Encoding: chunked that HttpClient is using by default. Is there any way to disable the usage of chunked encoding for POSTs from the client? 回答1: As said in Restlet mailing list, in Restlet version 2.1, you can set ClientResource#entityBuffering property to true to cache content in memory and prevent chunked encoding. 回答2: As a