首页新闻招聘找找看知识库

C# WebRequest出错:"服务器提交了协议冲突"

0
悬赏园豆:30 [已解决问题]

触发这个问题的C#代码如下:

var webReqeust = WebRequest.Create(ApiUrl);
webReqeust.Method = "DELETE";
using (var response = webReqeust.GetResponse()) { } 

错误信息:

System.Net.WebException: 服务器提交了协议冲突. Section=ResponseStatusLine
   在 System.Net.HttpWebRequest.GetResponse()

英文错误信息:

The server committed a protocol violation. Section=ResponseStatusLine
  + System.Net.HttpWebRequest.GetResponse()

请问如何解决?

C#
dudu的主页 dudu | 高人七级 | 园豆:32514
提问于:2017-06-12 15:14
< >
分享
最佳答案
0
webRequest.KeepAlive = false;//设置一下看看
收获园豆:30
MrNice | 老鸟四级 |园豆:2034 | 2017-06-12 15:34

KeepAlive设置为false的确可以了

var webReqeust = WebRequest.Create(ApiUrl) as HttpWebRequest;
webReqeust.Method = "DELETE";
webReqeust.KeepAlive = false;
using (var response = webReqeust.GetResponse()) { } 
dudu | 园豆:32514 (高人七级) | 2017-06-12 17:55
   您需要登录以后才能回答,未注册用户请先注册