apache-commons-httpclient

Is it possible to download files like PDF with HttpClient?

吃可爱长大的小学妹 提交于 2019-12-03 09:55:47
问题 I found some examples here on how to download a file but most of them seem to be using HttpURLConnection. is it possible to download files with HttpClient? 回答1: Using httpclient is pretty easy. Here's a link to it's tutorial. http://hc.apache.org/httpcomponents-client-ga/tutorial/html/fundamentals.html#d5e43 HttpClient httpclient = new DefaultHttpClient(); HttpGet httpget = new HttpGet(urltofetch); HttpResponse response = httpclient.execute(httpget); HttpEntity entity = response.getEntity();

Issue with trying to Login to a https secure using apache commons httpclient class

吃可爱长大的小学妹 提交于 2019-12-03 09:09:00
Iam trying to login to a https secured site using Apache commons httpclient. Iam not getting any way to pass the certificate along with my httprequest , since I cannot find any such classes in HttpClient Package. If anybody can guide me on where do I need to add the certificate handling? Any package to do it? Am open to ideas, any other way to do this in java. The platform must be only java however.. I have posted my code below. import java.net.MalformedURLException; import org.apache.commons.httpclient.*; import org.apache.commons.httpclient.cookie.CookiePolicy; import org.apache.commons

How do I pass the client certificate with HTTP client?

倾然丶 夕夏残阳落幕 提交于 2019-12-03 03:31:40
I want to use mutual SSL authentication between service A and B. I'm currently implementing passing the client certificate from service A in Java. I'm using Apache DefaultHttpClient to execute my requests. I was able to retrieve the client certificate for my service A from an internal credential manager and I keep it as an array of bytes. DefaultHttpClient client = new DefaultHttpClient(); byte [] certificate = localCertManager.retrieveCert(); I have very little experience in this area and I'd appreciate your help! I thought maybe it should be somehow passed through arguments in the HTTP

Kerberos connection using HTTP Client

我只是一个虾纸丫 提交于 2019-12-03 03:25:12
I'm writing HTTP connection with Kerberos authentication. I have "HTTP/1.1 401 Unauthorized". Could you recommend me what I should check? I think there's somethink trick, but I don't see it. May be I should set header "WWW-Authenticate" with "Negotiate"? Thank a lot in advanced for any help and ideas. public class ClientKerberosAuthentication { public static void main(String[] args) throws Exception { System.setProperty("java.security.auth.login.config", "login.conf"); System.setProperty("java.security.krb5.conf", "krb5.conf"); System.setProperty("sun.security.krb5.debug", "true"); System

Is it possible to download files like PDF with HttpClient?

 ̄綄美尐妖づ 提交于 2019-12-03 00:31:47
I found some examples here on how to download a file but most of them seem to be using HttpURLConnection. is it possible to download files with HttpClient? Using httpclient is pretty easy. Here's a link to it's tutorial. http://hc.apache.org/httpcomponents-client-ga/tutorial/html/fundamentals.html#d5e43 HttpClient httpclient = new DefaultHttpClient(); HttpGet httpget = new HttpGet(urltofetch); HttpResponse response = httpclient.execute(httpget); HttpEntity entity = response.getEntity(); if (entity != null) { long len = entity.getContentLength(); InputStream inputStream = entity.getContent(); /

Using HttpClient with SSL and certificates

99封情书 提交于 2019-12-02 10:23:27
问题 While I've been familiar with HTTPS and the concept of SSL, I have recently begun some development and found I am a little confused. The requirement was that I write a small Java application that runs on a machine attached to a scanner. When a document is scanned this is picked up and the file (usually PDF) sent over the internet to our application server that will then process it. I've written the application using Apache Commons libraries and HTTPClient. The second requirement was to

How can I POST using Java and include parameters and a raw request body?

守給你的承諾、 提交于 2019-12-01 15:09:13
问题 I am communicating with a web service that expects a POST parameter and also expect Request body. I have confirmed that such a POST request can be done using a REST Console I have, but I am unable to make such a request in Java using Apache libraries. In the code below, I am able to POST to the web service, and it correctly receives the contents of the variable raw_body. If I uncomment the first of the two commented lines, the web service receives the "fname" parameter, but it no longer

Set response encoding with HttpClient 3.1

给你一囗甜甜゛ 提交于 2019-12-01 09:24:14
I'm using org.apache.commons.httpclient.HttpClient and need to setup response encoding (for some reason server returns incorrect encoding in Content-Type). My way is to get response as raw bytes and convert to String with desired encoding. I'm wondering if there is some better way to do this (eg. setup HttpClient). Thanks for suggestions. I don't think there's a better answer using HttpClient 3.x APIs. The HTTP 1.1 spec says clearly that a client "must" respect the character set specified in the response header, and use ISO-8859-1 if no character set is specified. The HttpClient APIs are

Read multipart/mixed response in Java/Groovy

旧时模样 提交于 2019-11-30 23:41:17
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? 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); BodyPart part = multipart.getBodyPart(1); file = new File('/../../path/filename.pdf') file << part.content Have

How can I configure HTTPClient to authenticate against a SOCKS proxy?

二次信任 提交于 2019-11-30 15:57:17
问题 I need to set up proxy authentication against a SOCKS proxy. I found out this post giving instructions that appear to work with common HTTP proxies. httpclient.getHostConfiguration().setProxy("proxyserver.example.com", 8080); HttpState state = new HttpState(); state.setProxyCredentials(new AuthScope("proxyserver.example.com", 8080), new UsernamePasswordCredentials("username", "password")); httpclient.setState(state); Would that work with SOCKS proxies as well or do I have to do something