?
Solved

adding a header field in UrlConnection

Posted on 2000-03-13
3
Medium Priority
?
525 Views
Last Modified: 2006-11-17
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
0
Comment
Question by:ajayksh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Expert Comment

by:kbeier
ID: 2612329
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.
0
 
LVL 3

Expert Comment

by:yuvalg
ID: 2612346
What do you mean by "header" ?
Is that data that is transfered with each "message", or once per communication ?

yuval.
0
 

Accepted Solution

by:
kbeier earned 90 total points
ID: 2612566
HTTP Headers are messages sent between any agent (commonly your browser) and Internet web servers whenever you request a webpage. These headers contain information in fields.

As I understand it, every time you POST or GET something from a webserver, you should pass header information (fields) relating to your agent, what charset it accepts, what language it utilises etc to the web server which is serving you the page, but some of this information is not compulsory (perhaps someone could correct me here if I'm wrong - or further enlighten us all as to what is actually NECESSARY in a header since the RFC is rather vague about this! :-)).  For example, it's just good manners to let the web server you are POSTing to log your agent by passing it this info in the Agent field.  Otherwise you could just as easily pass your agent off as Mozilla or IE, which is what certain spam harvesters do...but that's off the topic. :-)
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
The viewer will learn how to implement Singleton Design Pattern in Java.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month15 days, 4 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question