• Post Reply Bookmark Topic Watch Topic
  • New Topic

Set the header fields for a HttpUrlConnection  RSS feed

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure if this is the right forum (servlet would be my second guess). I try to write a servlet, that is receives a request, processes it and calls as a result an URL to retrieve information there. The system needs to pass on header fields from the original request. Retrieving the header was easy... I got stuck when setting the header to an HttpURLConnection. This is what I tried:
URL url = new URL(targetURL);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
// Set the header
con.setRequestProperty("DisplayScheme","Winter");
con.setRequestProperty("LTPAToken",curUserToken);
// Post data
OutputStream out = connection.getOutputStream();
out.write(PayLoad.getBytes());
// Read the response;
String resultData = readURLResponse(con); // readURLResponse gets back
In general it returns anwers, but seems not to post the HTTP Header set with the setRequestProperty command. I'm sure it's a case of a java rookie missing out something.
Any hint?
:-) stw
 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I always use this baby:
http://jakarta.apache.org/commons/httpclient/
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!