0

1) How can I send specific request headers whilst a url.openConnection()?

2) Also, how can I, in addition, turn the request to a POST and send post data as well?

3) What document would you recommend to learn further more about url.openConnection() and its possibilities?

Thank you.

Phil
  • 13,875
  • 21
  • 81
  • 126

1 Answers1

2
  1. connection.addRequestProperty(headerName, headerValue);

  2. You should call connection.setRequestMethod("POST");, then call connection.getOutputStream() and write to this stream content of POST request.

  3. google: "java http post example" brings tons of documentation. Here is the first one: http://www.exampledepot.com/egs/java.net/post.html

AlexR
  • 114,158
  • 16
  • 130
  • 208
  • Hello, thank you. However, the most important part is missing. How do I select the IP address FROM which this request will be fired? Server has multiple IP addresses bind to it, multiple interfaces. I want to use a specific one for this request. I would really appreciate your help, thank you VERY MUCH! – Phil Feb 26 '12 at 15:32