2014-03-26 95 views
5

我從我的應用程序獲取Github數據。 第2個OAuth的步驟是好的,但在第三我有以下錯誤: 「服務器提交了協議違反第= ResponseStatusLine錯誤」。 這是我的代碼:使用Github API違反協議

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使用api V2時,與現在不同,這個代碼沒有問題。 因此,不能成爲.NET的限制,而是與Github服務器連接的東西。 有什麼建議嗎?

+0

您是否找到了解決方案?我遇到了同樣的問題,但我也得到了一些混合的響應(不同的線程,請求1也有請求2的響應)... – mnkypete

+0

也在這裏得到相同的錯誤。 Urgh :( –

回答

14

你需要設置的UserAgent這樣的:

webRequest.UserAgent = "YourAppName"; 

否則會給The server committed a protocol violation. Section=ResponseStatusLine錯誤。

+1

非常感謝...一直在尋找解決這個問題遍佈網絡。 – Akanksha

相關問題