C# 使用GitHub-C列出所有存储库

C# 使用GitHub-C列出所有存储库,c#,asp.net,C#,Asp.net,我用C编写的脚本有问题。我尝试在GitHub中列出所有公共存储库 这是我的密码: HttpWebRequest request = WebRequest.Create("https://api.github.com/repositories?since=364") as HttpWebRequest; request.Method = "GET"; request.Proxy = null; request.Content

我用C编写的脚本有问题。我尝试在GitHub中列出所有公共存储库

这是我的密码:

             HttpWebRequest request = WebRequest.Create("https://api.github.com/repositories?since=364") as HttpWebRequest;
        request.Method = "GET";
        request.Proxy = null;
        request.ContentType = "application/json";

        using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
        {
            StreamReader reader = new StreamReader(response.GetResponseStream());

                content1= reader.ReadToEnd();

        }
我有一个错误:

System.Net.WebException was unhandled by user code
 The server committed a protocol violation. Section=ResponseStatusLine
 Source=System


An exception of type 'System.Net.WebException' occurred in System.dll but was not handled in user code
在线使用

谢谢你的帮助

HttpWebRequest request = WebRequest.Create("https://api.github.com/repositories?since=364") as HttpWebRequest;
request.UserAgent = "TestApp";
    using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
    {
        StreamReader reader = new StreamReader(response.GetResponseStream());
        content1= reader.ReadToEnd();
    }

使用UserAgent是因为当您从浏览器请求url时,url服务于数据,但当应用程序不是服务器时,UserAgent是问题所在。尽管您可以看到相同的错误,但某些其他参数也丢失了。

请提供完整的异常消息,包括您可以看到的任何内部异常。完整异常:其他信息:服务器违反了协议。Section=responseStatusLine谢谢,效果很好!