user840718
user840718

Reputation: 1611

Protocol violation using GitHub API

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?

Upvotes: 5

Views: 1524

Answers (1)

Jaex
Jaex

Reputation: 4304

You need to set UserAgent like this:

webRequest.UserAgent = "YourAppName";

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

Upvotes: 18

Related Questions