Outgoing http requests not showing in Fiddler from tcpClient in C# - c#

I have a TCP-client written in C#, which sends HTTP requests. When I am sending requests I don't see them in Fiddler. When I send similar requests from Http requester I can see all requests.
What is the reason?

Fiddler registers itself as the default HTTP proxy. Applications are free to ignore that proxy. Your code needs to cooperate with Fiddler. It needs to find out what proxy is set and use it.
The built-in HTTP classes in .NET do that.

Related

How do I capture HTTP outgoing requests on my client?

I have a C# application and I want to capture outgoing http requests that have been made through the application (I can also identify that it was from the app because I have a specific server name).
When searching on the web all I could find was capturing incoming requests (so the code is on the server side) with TcpListener and HttpListener.
But the code must be client side so it must be outgoing requests.
And I cannot use any third party libraries (like FiddlerCore for example).
So I'm really looking for a code sample to start from.
Do you want to store the request or just access it for debugging?
If you are going after debugging, then you can use Fiddler. Fiddler is an HTTP debugging proxy server application. And if you are planning to modify or read data in the request or the response you can use HTTPRequestWrapper and HTTPResponseWrapper to access.

How to handle HTTP Connect in .NET?

I would like to handle HTTP on very low level - at the moment I'm stuck with HTTP CONNECT verb. It looks like HttpListener doesn't have access to these request because they are handled somewhere inside HTTP API or HTTP.SYS. I'm able to handle such requests with native TcpListener but in such case I would lose all HTTP functionality = I would implement HTTP from scratch.
I also checked FiddlerCore but it also handles these requests on some Win API layer. Is there any pure .NET HTTP stack?
Edit: I'm working on HTTP proxy with some additional request analysis and statistics so I don't want to lose HTTP parsing and in the same time I want to know about SSL connections.
Use Tcp* ans Socket*, not Http* related classes to use really low level in .NET.
TCP is at the bottom of HTTP protocol stack.
Use TCP sockets if you want it to, just use "winsock2.dll" interop calls form c#, and all related stuff like structure definitions etc, or use native C++
Well, if you are building your custom HTTP/HTTPS server or proxy and you don't mind third-party components, then our SecureBlackbox includes HTTP/HTTPS server components which let you do almost anything with any verb. Pure .NET, use any socket classes.
Ok. Again the problem is not in API but in developer :)
I have some test suite to test my implementation but the test suite was connecting directly (not as to a proxy) - that was the first problem. The second problem was that this test suite should use TcpClient instead of HttpWebRequest if I want to test Connect verb separately because HttpWebRequest uses it only internally when using proxy for HTTPS.

Listen to HTTP requests

I have a C# form application which I want to have listening for incoming HTTP requests from other computers.
How would I go about doing this?
For simple needs, the HttpListener class is a good and simple choice. There is an example on the linked MSDN page.
If, for some reason, you cannot use HttpListener, the process would be to listen to a port using TcpClient (or even the sockets API if you need the gritty details), and then implement the HTTP Protocol. I highly recommend HttpListener over rolling your own, unless you have specific requirements that HttpListener does not meet.
You can use ASP.NET Http Filters to intercept HTTP requests.
See more details here
If it's an asp.net application, you can check the http requests in the Application_BeginRequest event handler of your global.asax.

Why is WCF communication a tcp even if I say http in URI?

I have created a WCF server in a PC named PC1. I access the URI http://PC1:8000/ServiceModelSamples/Service using internet explorer from another PC named PC2.
When I debug the messages in Wireshark, I am confused that why there is no HTTP message, even though I specify "http://" in my URI. It only shows TCP protocol, there is no HTTP message or header.
Please advice
To wireshark, any browser request is just another TCP connection. As far as showing the HTTP protocol details is concerned, it might be guessing that traffic on a specific port (80) would be http. Since you are using a non-standard http port, it might not be able to do so.
To confirm this, try loading some other website/webpage (e.g. www.google.com) and see if it is able to show you http details. If it works, then next thing would be try and find some setting/configuration by which you can tell wireshark that it should treat traffic from another port (8000 in your case) as http traffic.
EDIT:
See this question as a guide to configure wireshark for http ports.
HTTP is an application layer protocol that sits on top of TCP, the transport layer protocol.
See http://en.wikipedia.org/wiki/TCP/IP_model for more information.
When you access the service using a browser, a "friendly" service responds to generate a web form to your browser. If you get a web page back in your browser, it is HTTP. That's not part of the "SOAP" spec, but it is part of the MS WCF stack supporting HTTP.
Then, if you fill it out, you might be POSTing or GETing the form, but POST is the default. That's also HTTP. GET is often disabled in WCF.
Then, you get back XMLish stuff in your browser, that also came by HTTP.
So you might just be missing an HTTP protocol decode in wireshark.
EDIT: I didn't see your URL included :8000. Wireshark won't decode that as HTTP unless you force it to, because it's not on the HTTP port. You can right-click on a port 8000 packet and say "follow conversation", and you'll see all the http goodness. You can also force wireshark to decode that stream as HTTP, which will let you "drill into" the packets past the TCP layer.

WCF ServiceRoute and Tcp

I have a WCF application hosted in IIS in which i use WsHttpBinding, with aspnetCompatibility since i want to use RouteTable functionality to route many calls to a single service.
every thing worked as expected, no problems here.
Then i added a tcp endpoint to the service(using its original url), and called the service using client, everything worked here, without a problem.
Then i modified the client url with routed url, and called the method using tcp endpoint, i got a socket error, which is what i expected.
But then i ran the wsHttp client with the routed url (which worked), and ran the tcp client with the routed url (which surprisingly worked)
Are tcp requests and http requests being routed through the same pipeline ?
As far as I know, the System.Web.Routing scenario is only supported for HTTP-based endpoints, since the netTcpBinding really doesn't use URLs in the same way.
--larsw
According to Microsoft's documentation on ServiceRoute, it is only designed to support extension-less base addresses over HTTP transport.

Categories

Resources