Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在不使用fiddler的情况下,将HttpWebRequest视为GetResponse之前的字符串_C#_.net_Httpwebrequest_Rfc_Windows - Fatal编程技术网

C# 在不使用fiddler的情况下,将HttpWebRequest视为GetResponse之前的字符串

C# 在不使用fiddler的情况下,将HttpWebRequest视为GetResponse之前的字符串,c#,.net,httpwebrequest,rfc,windows,C#,.net,Httpwebrequest,Rfc,Windows,在调用GetResponse方法之前,如何将HttpWebRequest对象视为字符串?我想在fiddler中看到请求的原始格式: Content-Type: multipart/form-data; boundary=---------------------------2600251021003 Content-Length: 338 -----------------------------2600251021003 Content-Disposition: form-data; na

在调用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>


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

app.config中的tracemode=“protocolonly”不可用recognized@brz网络,不要相信Visual Studio。只要运行你的代码,它就会工作。肯定有这样的因素。MSDN上甚至有这样的说明:我可以为特定的请求指定跟踪吗?