我正在尝试从我的应用程序发送与从浏览器发送相同的信息。以下是 Fiddler 捕获的部分数据:
POST http://something/ HTTP/1.1
Host: something.com
Connection: keep-alive
我被这个连接属性卡住了。如果我将属性 keep-alive 设置为 true,在 Fiddler 中我会看到:
代理连接:保持活动
如果我尝试将连接属性设置为 Keep-alive,则会收到以下错误:
不能使用此属性设置 Keep-Alive 和 Close。
如何编写代码以便在 Fiddler 中我可以看到:
连接:保持活动
我的完整代码:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://myUrl ");
request.Method = "POST";
request.ProtocolVersion = HttpVersion.Version11;
request.Accept = "*/*";
WebHeaderCollection headers = new WebHeaderCollection();
headers.Add("Accept-Encoding", "myEncoding");
headers.Add("Accept-Language", "myLang");
request.Headers = headers;
request.ContentType = "myContentType";
request.Referer = "myReferer";
request.UserAgent = "myUserAgent";
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "myData";
byte[] data = encoding.GetBytes(postData);
request.GetResponse().Close();