You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Patrick Mauro <pm...@apparentnetworks.com> on 2005/01/12 05:02:15 UTC

Receiving an attachment through http

Hi, I've got a situation where I make a request to a webserver,
http://server/foo.do?param=value <http://server/foo.do?param=value> .
The response is a webpage and a pdf attachment.  I've gotten it to work
if I use my web browser, if I connect to the url with my web browser I
get prompted to save or open the pdf.  However, when I try this through
httpclient I'm only getting the html page (which is never seen from the
web browser).
 
Here's my code for trying read the pdf from the http response:
 
GetMethod fileGet = new GetMethod(urlWithparameters);
HttpClient client = new HttpClient();
// this defines the protocol, host and port number for the connection
client.setHostConfiguration(
ProxyServices.getSysConfigServices().getWebServerConfig());
client.setConnectionTimeout(5000);
int status = client.executeMethod(fileGet);
// ... check for status codes in here
byte[] pdf = fileGet.getResponseBody();

My current theory as to why this doesn't work for me is that I believe
the server transmits the pdf through content-disposition=attachment
which I just read is not a core part of the http spec and is in fact a
seperate spec in its own right.  Plus, my understanding is that
HttpClient is intended to cover the core functionality of http...

If I'm not doing this right, any help would be greatly appreciated.  Or,
if my theory is correct, what package I might go through to resolve this
would be immensly helpful.

 

Thanks a lot!  Great package!

Patrick Mauro 


Re: Receiving an attachment through http

Posted by Roland Weber <RO...@de.ibm.com>.
Hello Patrick,

could you send a wire log so we can see what is
actually happening?
http://jakarta.apache.org/commons/httpclient/logging.html

I have two other possible explanations for the
behavior you described:

1) the server sends an HTTP redirect which is not handled
    automatically by HttpClient for some reason

2) the server sends an HTML page with some JavaScript
    or META tag in it that triggers a redirect

cheers,
  Roland





"Patrick Mauro" <pm...@apparentnetworks.com> 
12.01.2005 05:02
Please respond to
"HttpClient User Discussion"


To
<ht...@jakarta.apache.org>
cc

Subject
Receiving an attachment through http






Hi, I've got a situation where I make a request to a webserver,
http://server/foo.do?param=value <http://server/foo.do?param=value> .
The response is a webpage and a pdf attachment.  I've gotten it to work
if I use my web browser, if I connect to the url with my web browser I
get prompted to save or open the pdf.  However, when I try this through
httpclient I'm only getting the html page (which is never seen from the
web browser).
 
Here's my code for trying read the pdf from the http response:
 
GetMethod fileGet = new GetMethod(urlWithparameters);
HttpClient client = new HttpClient();
// this defines the protocol, host and port number for the connection
client.setHostConfiguration(
ProxyServices.getSysConfigServices().getWebServerConfig());
client.setConnectionTimeout(5000);
int status = client.executeMethod(fileGet);
// ... check for status codes in here
byte[] pdf = fileGet.getResponseBody();

My current theory as to why this doesn't work for me is that I believe
the server transmits the pdf through content-disposition=attachment
which I just read is not a core part of the http spec and is in fact a
seperate spec in its own right.  Plus, my understanding is that
HttpClient is intended to cover the core functionality of http...

If I'm not doing this right, any help would be greatly appreciated.  Or,
if my theory is correct, what package I might go through to resolve this
would be immensly helpful.

 

Thanks a lot!  Great package!

Patrick Mauro