Page 1 of 1

http header values

PostPosted: Wed Dec 19, 2012 9:37 pm
by jhb50
In order to access websites with domain protection, I need to set the Referer: value in the http header .

Your String openURL(URL url, String userAgent, Map<String,String> cookies) correctly sets the UserAgent:
but when I set
def cookies = [Referer: "http://www.cricfree.tv"]
wireshark shows the header as
Cookies: Referer=http://www.cricfree.tv\r\n
rather than the required
Referer: http://www.cricfree.tv\r\n

How do I set the Referer value?

Re: http header values

PostPosted: Wed Dec 19, 2012 11:51 pm
by zip
There is no shared method supporting custom headers. You will have to use a low level Java code to make the request. Try URLConnection and its setRequestProperty()

http://docs.oracle.com/javase/6/docs/ap ... .String%29

Re: http header values

PostPosted: Thu Dec 20, 2012 10:53 am
by r-win
I've had to use something similar to be able to POST to websites. You can find that here:
https://github.com/r-win/serviio-plugins/blob/master/OmroepNL.groovy#L64

I know I don't set any headers there, because they're not required. In your case, you can just add a line:
  Code:
connection.addRequestProperty('Referer', 'http://www.cricfree.tv')

Re: http header values

PostPosted: Thu Dec 20, 2012 12:44 pm
by jhb50
Much appreciated. Thank you both. It works great.