C#調取接口時報錯:服務器提交了協議沖突. Section=ResponseStatusLine


 1   private Dictionary<string, Object> GetLocation(string imei)
 2         {
 3             #region===代碼===
 4             string serviceAddress = string.Format("http://localhost/api/car/getlastinfo?imei={0}&key=xxxxx",imei);
 5             HttpWebRequest req = (HttpWebRequest)WebRequest.Create(serviceAddress);
 6             req.Method = "get";
 7             req.KeepAlive = false;  8             var resp = new StreamReader(((HttpWebResponse)req.GetResponse()).GetResponseStream(), Encoding.GetEncoding("utf-8"));
 9             string res = resp.ReadToEnd();
10             resp.Close();
11             Dictionary<string, Object> dic = null;
12             if (res != "")
13             {
14                 dic = JsonConvert.DeserializeObject<Dictionary<string, Object>>(res);
15             }
16             return dic;
17             #endregion===代碼===
18         }

解決:設置  req.KeepAlive = false;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM