windows 在不使用提琴手的情况下,在 GetResponse 之前将 HttpWebRequest 视为字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3590650/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
See HttpWebRequest as string before GetResponse without using fiddler
提问by Brij
How can i see HttpWebRequest object as string before calling GetResponse method? I want to see raw format of request something like this as in fiddler:
在调用 GetResponse 方法之前,如何将 HttpWebRequest 对象视为字符串?我想在 fiddler 中看到类似这样的请求的原始格式:
Content-Type: multipart/form-data; boundary=---------------------------2600251021003
Content-Length: 338
-----------------------------2600251021003 Content-Disposition: form-data; name="UPLOAD_FILEName"; filename="Searchlight062210 w price.csv" Content-Type: application/vnd.ms-excel
,,,,,
-----------------------------2600251021003
Content-Disposition: form-data; name="submit"
submit
-----------------------------2600251021003--
I tried following code, but not worked because stream is not readable.
我尝试了以下代码,但没有奏效,因为流不可读。
string GetRequestString(HttpWebRequest req)
{
Stream stream2 = req.GetRequestStream();
StreamReader reader2 = new StreamReader(stream2);
return reader2.ReadToEnd();
}
采纳答案by Darin Dimitrov
If it is for logging purposes you could activate tracing by putting this in your app/web.config:
如果是为了记录目的,您可以通过将其放在您的 app/web.config 中来激活跟踪:
<system.diagnostics>
<sources>
<source name="System.Net.Sockets" tracemode="protocolonly">
<listeners>
<add name="System.Net.Sockets" type="System.Diagnostics.TextWriterTraceListener" initializeData="network.log" />
</listeners>
</source>
</sources>
<switches>
<add name="System.Net.Sockets" value="Verbose"/>
</switches>
<trace autoflush="true" />
</system.diagnostics>
Run your code and look at the generated log file.
运行您的代码并查看生成的日志文件。