HttpWebRequest的不只是工作的时候小提琴手正在运行 [英] HttpWebRequest doesn't work except when fiddler is running

查看:133
本文介绍了HttpWebRequest的不只是工作的时候小提琴手正在运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是我所遇到的最不可思议的问题。我有一段代码提交POST到URL。该代码不工作的时候都不提琴手没有运行抛出任何异常,但是,当小提琴手正在运行,代码帖中的数据successfuly。我有机会到后页,所以我知道,如果数据已经公布与否。这可能是很无感,但它是我遇到的情况,我感到非常困惑。

This is probably the weirdest problem I have run into. I have a piece of code to submit POST to a url. The code doesn't work neither throws any exceptions when fiddler isn't running, However, when fiddler is running, the code posts the data successfuly. I have access to the post page so I know if the data has been POSTED or not. This is probably very non-sense, But it's a situation I am running into and I am very confused.

byte[] postBytes = new ASCIIEncoding().GetBytes(postData);
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://myURL);
req.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.224 Safari/534.10";
req.Accept = "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
req.Headers.Add("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.3");
req.Headers.Add("Accept-Language", "en-US,en;q=0.8");
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = postBytes.Length;
req.CookieContainer = cc;
Stream s = req.GetRequestStream();
s.Write(postBytes, 0, postBytes.Length);
s.Close();


推荐答案

如果你不叫 GetResponseStream(),那么你不能关闭的反应。如果你不 T保持紧密的响应,那么你最终在一个糟糕的状态 .NET 插座,你必须关闭,以防止你的后面的请求干扰的响应。

If you don't call GetResponseStream() then you can't close the response. If you don't close the response, then you end up with a socket in a bad state in .NET. You MUST close the response to prevent interference with your later request.

这篇关于HttpWebRequest的不只是工作的时候小提琴手正在运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆