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?

