如何在调用GetResponse方法之前将HttpWebRequest对象视为string? 我想要看到原始格式的请求像这样的小提琴手:
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--
我试过下面的代码,但没有工作,因为stream是不可读的。
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.TextWriterTracelistner" initializeData="network.log" /> </listeners> </source> </sources> <switches> <add name="System.Net.Sockets" value="Verbose"/> </switches> <trace autoflush="true" /> </system.diagnostics>
运行您的代码并查看生成的日志文件。