当我尝试按照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;
答案 0 :(得分:0)
您自己引用的文档说
Exception Condition
ArgumentException The value of Connection is set to Keep-alive or Close.
因此,如果要设置connection
属性,则不应指定KeepAlive
属性。