无法在HttpWebRequest中删除Connection头

时间:2015-12-27 19:58:37

标签: c# .net-3.5

当我尝试按照reference HttpWebRequest.Connection 设置为 null 时,该行会抛出 ArgumentException ,包含任何< strong> HttpWebRequest.KeepAlive 值。有什么方法可以摆脱那个标题好吗?

更新:代码片段呈现手头的问题

HttpWebRequest request1 = (HttpWebRequest) WebRequest.Create ( "http://google.com/" );
request1.Connection = null;

HttpWebRequest request2 = (HttpWebRequest) WebRequest.Create ( "http://google.com/" );
request2.KeepAlive = false;
request2.Connection = null;

1 个答案:

答案 0 :(得分:0)

您自己引用的文档说

Exception                      Condition 
ArgumentException   The value of Connection is set to Keep-alive or Close.

因此,如果要设置connection属性,则不应指定KeepAlive属性。