jQuery in Action, 3rd edition
The moose likes Servlets and the fly likes URL reader error in my web application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "URL reader error in my web application" Watch "URL reader error in my web application" New topic

URL reader error in my web application

varun bihani
Ranch Hand

Joined: Aug 11, 2003
Posts: 96
I am trying to use this code in my servlet:
public static void main(String[] args) throws Exception {
URL yahoo = new URL("http://images.google.com/images?q=this");
BufferedReader in = new BufferedReader(new InputStreamReader(yahoo

String inputLine;

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


but it gives this error :
java.io.IOException: Server returned HTTP response code: 403 for URL: http://images.google.com/images?q=this
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:814)
at java.net.URL.openStream(URL.java:913)
at URLReader.main(URLReader.java:8)

This works for yahoo image search but not for google..
Google image search works with .NET code available at http://www.codeproject.com/cs/library/google_image_search_api.asp
but it doesnt work with java
Please help.

<a href="http://www.galaxyweblinks.com" target="_blank" rel="nofollow">www.galaxyweblinks.com</a><br /><a href="http://www.freechatcode.com" target="_blank" rel="nofollow">www.freechatcode.com</a><br /><a href="http://www.onlinefamilytreemaker.com" target="_blank" rel="nofollow">www.onlinefamilytreemaker.com</a>
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63351

Have you looked up what a 403 error means?

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
varun bihani
Ranch Hand

Joined: Aug 11, 2003
Posts: 96
I know. 403 is Access forbidden. but why does it work on .NET and not on Java ?
alban maillere

Joined: Nov 06, 2006
Posts: 6
I know google check your user agent ...
try something like this
URLConnection urlconnection = yahoo.openConnection();
"Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)");

while(true){<br /> this.put(BeerFactory.newInstance());<br />}
I agree. Here's the link: http://aspose.com/file-tools
subject: URL reader error in my web application
It's not a secret anymore!