5

I'm getting data from Github for my application. The first 2 OAuth steps are ok, but in the third I got the following error: "the server committed a protocol violation. Section=ResponseStatusLine ERROR" This is my code:

protected String WebRequest(string url)
    {
        url += (String.IsNullOrEmpty(new Uri(url).Query) ? "?" : "&") + "access_token=" + _accessToken;
        HttpWebRequest webRequest = System.Net.WebRequest.Create(url) as HttpWebRequest;
        webRequest.Method = "GET";
        webRequest.ServicePoint.Expect100Continue = false;
        try
        {
            using (StreamReader responseReader = new StreamReader(webRequest.GetResponse().GetResponseStream()))
                return responseReader.ReadToEnd();
        }
        catch
        {
            return String.Empty;
        }
    }

The program goes in exception after using the StreamReader object, that returns me the error. If I follow these instructions The server committed a protocol violation. Section=ResponseStatusLine ERROR , the error turns into "403 forbidden". When Github used api V2, different from now, there was no problem with this code. So, can't be a .NET limitation but something connected with Github server. Any suggestions?

Community
  • 1
  • 1
user840718
  • 1,563
  • 6
  • 29
  • 54
  • Did you find a solution for this? I'm running into the same problem, but I've also got some mixed up responses (different threads, request 1 has also the response from request 2)... – mnkypete Sep 10 '14 at 15:54
  • Also getting the same error here. Urgh :( – Pure.Krome Nov 04 '14 at 22:13

1 Answers1

18

You need to set UserAgent like this:

webRequest.UserAgent = "YourAppName";

Otherwise it will give The server committed a protocol violation. Section=ResponseStatusLine error.

Jaex
  • 4,204
  • 2
  • 34
  • 56