Listen to HTTP requests - c#

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.

Related

Sending an event from my REST webapi server to a specific client in c#

So I have a .NET project and my goal is to send an event to a specific user from the server. This event of course will have all kind of information, the ideal way would be for it to be similar to the REST requests from client/server... But I can't think my way through it. I've heard terms like sockets and stuff and someone told me that I could do it with a system similar to message system but can't find anything about it. Here is a conceptual example
I would recommend you checking out SignalR which is a protocol-wrapper over port 80 (the one browsers and web traffic uses). This way you can have the server send stuff to the client whenever the server wants. The more basic approach is to let the client poll the client (send a GET/POST-request) in intervals (~once a second) and return your information in the poll request response.

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.

Outgoing http requests not showing in Fiddler from tcpClient in 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.

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.

Is out there any sample of reading http requests using TCP socket collecting data from them (like emulating Http server in some way)

Is out there any sample of reading http requests using TCP socket collecting data from them (like emulating Http server in some way) so I wanna to keep data like senders IP:PORT, request body and so on.
So has any one seen such thing in OpenSource projects or do you know how to create it? (if so please provide siple code example)
In retrospect, HTTP is not the easiest protocol to parse. If it were designed from scratch today, it would be very different.
First off, use ASP.NET if possible. If you can't use ASP.NET, then take a look at the HttpListener class.

Categories

Resources