• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

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/
 
Destiny's powerful hand has made the bed of my future. And this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic