Link to home
Start Free TrialLog in
Avatar of ajayksh
ajayksh

asked on

adding a header field in UrlConnection

Hi,

How do i add an extra field in the header while doing a POST from my java pgm. I am using a UrlConnection to POST the data.

Do I need to use UrlConnection.setRequestProperty() method ???


Thanx
ajay
Avatar of kbeier
kbeier

Hi Ajay,

I'm not sure what you mean by "extra" field, but you can certainly set headers using UrlConnection.setRequestProperty().  For example:

//set the agent in the header
UrlConnection.setRequestProperty("User-Agent", "MyAgent/v1.00");

//set the "from" IP in the header        UrlConnection.setRequestProperty("From", IP);
                          UrlConnection.setRequestProperty("Accept", "text/html, text/plain");
                          UrlConnection.setRequestProperty("Accept-Charset", "iso-8859-1");
                          UrlConnection.setRequestProperty("Accept-Language", "en-gb");

You should read RFC1945 for more information about headers.
What do you mean by "header" ?
Is that data that is transfered with each "message", or once per communication ?

yuval.
ASKER CERTIFIED SOLUTION
Avatar of kbeier
kbeier

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial