在调用 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--
我尝试了以下代码,但没有成功,因为流不可读。
string GetRequestString(HttpWebRequest req)
{
Stream stream2 = req.GetRequestStream();
StreamReader reader2 = new StreamReader(stream2);
return reader2.ReadToEnd();
}
最佳答案
如果它是为了记录目的,你可以通过将它放在你的 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>
运行您的代码并查看生成的日志文件。
关于c# - 在不使用 fiddler 的情况下将 HttpWebRequest 视为 GetResponse 之前的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3590650/