Why Google searh doesn't work using URL connection?

My goal is to search Web pages with Google using URL connection. For example if I want to search for keyword "sun" the URL will be

http://www.google.hr/search?hl=hr&q=sun&btnG=Google+pretraga&meta=

Only the keyword changes in this code, so I assumed that I can searh the web only changing the keyword in url connection: But it doesn't work with Google, and it works with MSN search

My code is:

import java.net.*;

import java.io.*;

publicclass URLReader{

publicstaticvoid main(String[] args)throws Exception{

URL yahoo =new URL("http://www.google.hr/search?hl=hr&q=sun&btnG=Google+pretraga&meta=");

URLConnection yc = yahoo.openConnection();

BufferedReader in =new BufferedReader(

new InputStreamReader(

yc.getInputStream()));

String inputLine;

while ((inputLine = in.readLine()) !=null)

System.out.println(inputLine);

in.close();

}

}

End the resul is:

... server returned HTTP response code: 403for URL :http//www......

I found out that HTTP error 403 means Forbidden! Is this a reason? Is there any other way to searh with Google from my java code?

[1872 byte] By [Zdravkoa] at [2007-11-26 19:24:38]
# 1
Check reply #2 by user Woogley from this thread: http://forum.java.sun.com/thread.jspa?threadID=787097
prometheuzza at 2007-7-9 21:47:36 > top of Java-index,Java Essentials,Java Programming...
# 2
Thanks, a lot!!
Zdravkoa at 2007-7-9 21:47:36 > top of Java-index,Java Essentials,Java Programming...
# 3
> Thanks, a lot!!You're welcome.; )
prometheuzza at 2007-7-9 21:47:36 > top of Java-index,Java Essentials,Java Programming...
# 4
You can use URLConnection too; see the method URLConnection.addRequestProperty().
sjasjaa at 2007-7-9 21:47:36 > top of Java-index,Java Essentials,Java Programming...
# 5
Thanks you sjasja, This works even better
Zdravkoa at 2007-7-9 21:47:36 > top of Java-index,Java Essentials,Java Programming...
# 6
> Check reply #2 by user Woogley from this thread:> http://forum.java.sun.com/thread.jspa?threadID=787097Thats a neat hack. Very neat to be more precise.
qUesT_foR_knOwLeDgea at 2007-7-9 21:47:36 > top of Java-index,Java Essentials,Java Programming...