6

如何在调用 GetResponse 方法之前将 HttpWebRequest 对象视为字符串?我想在提琴手中看到类似这样的请求的原始格式:

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();  

        }
4

1 回答 1

6

如果它是用于记录目的,您可以通过将其放入您的 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>

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

于 2010-08-28T11:58:18.313 回答