2010-08-28 49 views
5

如何在调用GetResponse方法之前将HttpWebRequest对象视为字符串?我希望看到的要求是这样的raw格式作为小提琴手:请参阅HttpWebRequest作为GetResponse之前的字符串,而不使用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(); 

     } 

回答

6

如果是为了记录的目的,你可以通过激活把这个在您的应用程序/ 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> 

运行你的代码,并查看生成的日志文件。

+1

tracemode =“protocolonly”in app.config is not accepted – Brij 2010-08-28 12:29:58

+0

@brz dot net,不要相信Visual Studio。只需运行你的代码,它就可以工作。肯定有这样的元素。它甚至在MSDN上声明:http://msdn.microsoft.com/en-us/library/ty48b824.aspx – 2010-08-28 12:31:39

+0

+1伟人!意味着不需要小提琴手。 – Brij 2010-08-28 12:45:26

相关问题