• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Set the header fields for a HttpUrlConnection

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I always use this baby:
http://jakarta.apache.org/commons/httpclient/
 
if you think brussel sprouts are yummy, you should try any other food. And this tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic