Talk:Rosetta Code/Rank languages by popularity: Difference between revisions
Content deleted Content added
403 Problem |
|||
Line 556:
gets a 403 (Forbidden) response.
I found a question on Stack Overflow (related to another RC task) that suggested setting the http Agent property of the connection and it seems that is correct - by default, Java sets the user agent which stops the above code working.
Setting the user agent to "" appears to work, as does pretending to be a browser...
<pre>
URL url = new URL( ... );
URLConnection uc = url.openConnection();
uc.setRequestProperty( "User-Agent", "" );
BufferedReader bfr = new BufferedReader( new InputStreamReader( uc.getInputStream() ) );
String line = bfr.readLine();
etc...
</pre>
|