aspose file tools*
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
JavaRanch » Java Forums » Java » Servlets
Bookmark "URL reader error in my web application" Watch "URL reader error in my web application" New topic
Author

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
.openStream()));

String inputLine;

while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);

in.close();

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
Marshal

Joined: Jan 10, 2002
Posts: 61648
    
  67

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
Greenhorn

Joined: Nov 06, 2006
Posts: 6
I know google check your user agent ...
try something like this
URLConnection urlconnection = yahoo.openConnection();
urlconnection.setRequestProperty("User-Agent",
"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