在 GetResponse 之前将 HttpWebRequest 视为字符串,而不使用 fiddler

发布于 2024-09-16 16:38:03 字数 826 浏览 7 评论 0原文

在调用 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();  

        }

How can i see HttpWebRequest object as string before calling GetResponse method? I want to see raw format of request something like this as in 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-- 

I tried following code, but not worked because stream is not readable.

 string GetRequestString(HttpWebRequest req)
        {
            Stream stream2 = req.GetRequestStream(); 
            StreamReader reader2 = new StreamReader(stream2);
            return reader2.ReadToEnd();  

        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧街凉风 2024-09-23 16:38:03

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

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

If it is for logging purposes you could activate tracing by putting this in your 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>

Run your code and look at the generated log file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文