我正在为我的应用程序从Github获取数据。前两个OAuth步骤没问题,但在第三个步骤中我得到了以下错误:“服务器提交了一个违反协议的错误。Section=ResponseStatusLine错误”这是我的代码:
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;
}
}程序在使用StreamReader对象后发生异常,这将返回错误。如果我遵循这些指令The server committed a protocol violation. Section=ResponseStatusLine ERROR,错误变成"403禁止“。当Github使用V2接口时,与现在不同的是,这段代码没有问题。所以,不能是.NET的限制,而是与Github服务器相关的东西。有什么建议吗?
发布于 2014-11-06 17:44:35
您需要像这样设置UserAgent:
webRequest.UserAgent = "YourAppName";否则,它将给出The server committed a protocol violation. Section=ResponseStatusLine错误。
https://stackoverflow.com/questions/22649419
复制相似问题