Talk:Rosetta Code/Rank languages by popularity: Difference between revisions

Content added Content deleted
(403 Problem)
Line 556: Line 556:


gets a 403 (Forbidden) response.
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. Is this necessary? I don't see anything like this in the other languages solutions?
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. Interestingly, the .NET default is not to set the user agent which is presumably why the C# sample works.


Setting the user agent to "" appears to work, as does pretending to be a browser...
[[User:Tigerofdarkness]]

<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>