http referer in java

48 views
Skip to first unread message

Areej

unread,
Jul 2, 2009, 7:44:24 AM7/2/09
to Google AJAX APIs
hi,

I'm trying to create a java application in which I'm using the java
code snippet provided by Google
"
URL url = new URL("http://ajax.googleapis.com/ajax/services/search/web?
v=1.0&q=Paris%20Hilton");URLConnection connection = url.openConnection
();connection.addRequestProperty("Referer", "http://www.mysite.com/
index.html");String line;StringBuilder builder = new StringBuilder
();BufferedReader reader = new BufferedReader(new InputStreamReader
(connection.getInputStream()));while((line = reader.readLine()) !=
null) { builder.append(line);} "

how should I add http referer and the key, I already had a key and I
don't know where should I add it to the java code???

Jeremy Geerdes

unread,
Jul 2, 2009, 8:29:35 AM7/2/09
to Google-AJAX...@googlegroups.com
You need to add this line to your code after you've initialized your
connection:

connection.addRequestProperty("Referer", "http://www.mysite.com/index.html
");

You don't have to worry about the API key. It's not required.

Jeremy R. Geerdes
Effective website design & development
Des Moines, IA

For more information or a project quote:
http://jgeerdes.home.mchsi.com
http://jgeerdes.blogspot.com
http://jgeerdes.wordpress.com
jgee...@mchsi.com

Unless otherwise noted, any price quotes contained within this
communication are given in US dollars.

If you're in the Des Moines, IA, area, check out Debra Heights
Wesleyan Church!

And check out my blog, Adventures in Web Development, at http://jgeerdes.blogspot.com
!
Reply all
Reply to author
Forward
0 new messages