Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Content of HTTPUrlConnection  RSS feed

 
Johannes Postma
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I retrieve the whole content of a the response of a HTTPUrlConnection (including headers and body)? E.g.

Statuscode: 200
Content-length: 1582
Content-type: tex/html

<html>
<body>
...
</body>
</html>
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can get the headers through the various getHeaderField(s) methods of HttpURLConnection and its superclass. I don't think you can get the entire dump of the return short of connecting directly with a socket, making a request and reading the response.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've done it the socket route. It's a bit of a pain because you have to construct all headers for the request, too. Get an HTTP sniffer and watch what's going over the wire both ways to see what the headers look like. You may be able to catch a set from the sniffer and copy them right into your code to send them again later.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!