获得从HttpWebRequest的请求/响应TCP连接HttpWebRequest、TCP

2023-09-04 02:52:58 作者:你们俩个会得到报应的i

我想获得关于正在发生的事情,当我连接到一个网站在一个较低的水平比HttpWebRequest的更多信息和HttpWebResponse给我。我使用C#。

I am trying to get more information about what is going on when I connect to a website at a lower level than what HttpWebRequest and HttpWebResponse gives me. I am using C#.

我希望能够看到有关DNS查找,花了建立连接(如果成立一个新的连接)的时间信息。 HttpWebRequest和在更高层次上比这个HttpWebResponse工作,我想询问是否有获得潜在的TcpClient对象(或其他低级别的对象,他们使用)的方式。

I would like to be able to see information about the dns lookup and the time it took to establish a connection (if a new connection was established). HttpWebRequest and HttpWebResponse work at a higher level than this and I want to ask if there is a way of getting the underlying TcpClient object (or whatever low level object they use).

如果这是不可能的,那么有没有办法抓住和操纵的。NET是保持连接的列表,而无需通过HttpWebRequest的或HttpWebResponse得到它?

If it is not possible, then is there a way to grab and manipulate a list of the connections that .net is maintaining without getting it through HttpWebRequest or HttpWebResponse?

我不能改变我的工作使用TcpClient的应用程序,因为这太耗费时间来实现所有的HTTP的东西可靠。

I can't change the application I am working on to use TcpClient because it would be too time consuming to implement all the http stuff reliably.

推荐答案

这是我能得到最好的,你是要创建具有以下信息的app.config文件:

The best that I can get you is to create an app.config file with the following information:

<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
    <system.diagnostics>
        <trace autoflush="true" />
            <sources>
                <source name="System.Net" maxdatasize="1024">
                    <listeners>
                        <add name="MyTraceFile"/>
                    </listeners>
                </source>
              <source name="System.Net.Sockets" maxdatasize="1024">
                    <listeners>
                        <add name="MyTraceFile"/>
                    </listeners>
                </source>  
           </sources>


            <sharedListeners>
                <add
                  name="MyTraceFile"
                  type="System.Diagnostics.TextWriterTraceListener"
                  initializeData="System.Net.trace.log"
                />
            </sharedListeners>
            <switches>
                <add name="System.Net" value="Verbose" />
              <add name="System.Net.Sockets" value="Verbose" />
            </switches>
    </system.diagnostics>
</configuration>

这将启用跟踪,并踢了一个名为System.Net.trace.log在你的应用程序文件夹中的日志文件。你不会得到所有的信息,你正在寻找和它不是应用程序运行时很容易消耗的,但至少你并不需要有一个第三方程序运行。它不记录太多,但有一些信息的在那里至少

This will enable tracing and will kick out a log file named "System.Net.trace.log" in your app folder. You aren't going to get all of the information that you're looking for and its not easily consumable while the app is running but at least you don't need to have a third-party program running. Its not documented too much but there's some information out there at least.