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();
}
1 个解决方案
#1
6
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.
运行您的代码并查看生成的日志文件。
#1
6
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.
运行您的代码并查看生成的日志文件。