How to capture http request/response traffic resul

2019-09-18 09:38发布

问题:

I want to Capture Http Request/Response Traffic results(URL,Method,Type etc) with c# Windows Form App as manually.

An Example : Run ie explorer-> Tools -> F12 Developer Tools->Network Tab-Star Capture

How can I solve this problem. (Any use of the sdk. winpcap etc) How to trace a road?

回答1:

Try the below:

...
HttpWebRequest request =(HttpWebRequest)WebRequest.Create(HttpUtility.UrlDecode(<url>));
...
try
{
     HttpWebResponse response =(HttpWebResponse)request.GetResponse();
     WebHeaderCollection headers = response.Headers;
     ...
}
catch(WebException exc) { "HTTP EXCEPTION: " + exc.Message +" " + exc.Status; }
catch(ProtocolViolationException exc) { exc.Message; }
catch(UriFormatException exc)         { exc.Message; }
catch(NotSupportedException exc)      { exc.Message; }
catch(IOException exc)                { exc.Message; }