Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protocol violation using Github api

Tags:

c#

.net

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?

like image 286
user840718 Avatar asked Mar 26 '14 00:03

user840718


1 Answers

You need to set UserAgent like this:

webRequest.UserAgent = "YourAppName";

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

like image 150
Jaex Avatar answered Nov 01 '22 04:11

Jaex