First of all lets build a connection object, which we'll use at this post.
String url = "http://www.google.com/";
URLConnection urlConnection = new URL(url).openConnection();
Now we need to add a referer url with the urlConnection. The setRequestProperty() method of the URLConnection class is pretty useful for this kind of task.
Lets add an user agent with the request. People used to use lots of funny agent, we are considering our Opera as user agent.
Do you want to add some cookie with your request header? It is also available for you.
Above three are the common headers that people used to add on request header. But its open to use more. For example to request GZip content, you can add below line of code.
There are other headers like Accept-Charset, Accept-Language, Accept you can use too.
I have just shown you the way, its now upto you how you'll use it.