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

(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. IsInterestingly, thisthe necessary?.NET Idefault don'tis seenot anythingto likeset thisthe inuser agent which is presumably why the otherC# languagessample solutions?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>
3,068

edits