Get basic tcp connection from HttpWebRequest / Response

I am trying to get more information about what happens when I connect to a website at a lower level than the HttpWebRequest and HttpWebResponse give me. I am using C #.

I would like to be able to see the dns search information and the time required 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 to get the underlying TcpClient object (or any other low-level object that they use).

If this is not possible, then is there a way to capture and process the list of connections that .net supports without getting it through HttpWebRequest or HttpWebResponse?

I cannot change the application I'm working on to use TcpClient, because there is too much time for the reliable implementation of the entire http file.

+3
source share
3 answers

The best I can get 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>

This will track and issue a log file named "System.Net.trace.log" in your application folder. You will not get all the information you are looking for, and it is not easy to spend while the application is running, but at least you do not need to run a third-party program. It has not been documented too much, but there is some information there, at least.

+3
source

Use Wireshark, this is the best way to find out all this.

+2

If not Wireshark, use Fiddler .

+1
source

Source: https://habr.com/ru/post/1783246/


All Articles