简体   繁体   English

调试.net的WebClient

[英]Debugging .net's WebClient

Is there any good way (short of installing WireShark) to get the raw http request data sent to a webserver? 有没有什么好的方法(没有安装WireShark)来获取发送到网络服务器的原始http请求数据? I suspect the request I'm sending is incorrect or malformed but I don't know how to get at the raw request string that its sending to the webserver with a call to WebClient.UploadValues. 我怀疑我发送的请求不正确或格式错误但我不知道如何通过调用WebClient.UploadValues获取它发送到Web服务器的原始请求字符串。

Fiddler it's among us, Windows Developers, for quite some time, and even though it was bought by Telerik it's still one of the best tools to debug everything that goes on the wire. Fiddler在我们这些Windows开发人员中已经有一段时间了,即使它被Telerik收购,它仍然是调试线路上所有内容的最佳工具之一。

By the way, Fiddler is not only meant for ".NET WebClient", it's for everything that is happening in your computer throughout your network, and extremely helpful when debug ajax requests in javascript! 顺便说一句,Fiddler不仅适用于“.NET WebClient”,它适用于整个网络中计算机中发生的所有事情,在javascript中调试ajax请求时非常有用!

Install and fire it up 安装并启动它

  • On the left side, you will have all objects going through the "wire" with nice color coding 在左侧,您将通过“电线”使所有对象具有良好的颜色编码
  • On the Right side, everything that you can know about a selected request/response 在右侧,您可以了解有关所选请求/响应的所有信息
  • The Right side is divided in 2 parts vertically, top area means request , bottom area means response 右侧垂直分为两部分,顶部区域表示请求 ,底部区域表示响应

在此输入图像描述

Just select the request you sent on the left side, and on the right side choose Inspector and on top, select either Header (to see the full headers) or Raw to see the full text that was sent, and on the bottom do the same. 只需选择您在左侧发送的请求,然后在右侧选择Inspector ,在顶部选择Header (查看完整标题)或Raw以查看已发送的全文,并在底部执行相同操作。

If you're not getting any information on the response, set the Transformer to No Compression so you can see the entire response, even if it was compressed. 如果您没有获得有关响应的任何信息,请将Transformer设置为No Compression,这样您就可以看到整个响应,即使它已被压缩。

For more, see the tutorials on their page 有关更多信息,请参阅其页面上教程

Also, install the Syntax Highlighting Addon... it's very useful 另外,安装语法高亮显示插件...它非常有用


For your particular issue: 对于您的特定问题:

  1. open Fiddler 打开提琴手
  2. on your webpage, do everything until the moment you click in an action to perform what you need 在您的网页上,执行所有操作,直到您单击某个操作以执行所需操作为止
  3. Go back to Fiddler and clear all requests Edit > Remove > All Sessions or Ctrl + X 返回Fiddler并清除所有请求编辑>删除>所有会话或Ctrl + X.
  4. click your link or button that would make that request you need to debug 单击您需要调试的请求的链接或按钮
  5. see what's going on on the list 看看列表上发生了什么
  6. click on the request (on the left side) 点击请求(左侧)
  7. choose Raw in the Inspector Inspector中选择Raw
  8. see the response as well by clicking Raw on the bottom part of the request details 通过单击请求详细信息底部的Raw来查看响应
  9. see all other views and find the problem 查看所有其他视图并找到问题所在

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM