1

I am using WebClient to send some request to github api.

var wc = new WebClient();
wc.Headers.Add("user-agent", "notempty"); 
wc.Headers.Add("authorization", "basic " + Convert.ToBase64String("user:password"));
var response = wc.DownloadString(url + "/labels");
...
var response = wc.DownloadString(url + "/issues");

First I query all labels and then all issues

However on the 2nd DownloadString I get the following exception:

Unhandled Exception: System.Net.WebException: The server committed a protocol violation. Section=ResponseStatusLine at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request) at System.Net.WebClient.DownloadString(Uri address)

I don't get the exception if I set the useragent after first DownloadString. Why is that?

Jenny
  • 572
  • 4
  • 16

0 Answers0