Talk:Rosetta Code/Rank languages by popularity: Difference between revisions
Talk:Rosetta Code/Rank languages by popularity (view source)
Revision as of 19:47, 25 August 2015
, 8 years ago→Accessing RC via Java
(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>
|