I have a web application that communicates between two different web applications (one receiver and one sender, the sender communicates with my application, and my application communicates with both).
A regular scenario is that the sender sends a HttpRequest to my application, and I receive it in an HttpHandler. This in turn sends the HttpContext to some businesslogic to do some plumbing.
After my business classes are finished storing data (some logging etc), I want to relay the same request with all the headers, form data etc to the receiver application. This must be sent from the class, and not the HttpHandler.
The question is really - how can I take a HttpContext object, and forward/relay the exact same request only modifying the URL from http://myserver.com/ to http://receiver.com.
Any code examples in preferable c# would be great!
HttpContext includes the Request property, which in turn contains the Headers collection. It should be all the information you need.
possiblly something like:
Then call the get response
This will have the same HTTP headers as the original request.
I have an extension method on
HttpResponseBase
to copy an incoming request to an outgoing request.Usage:
Source:
Here's some good relay code in VB.NET using MVC.
GLOBAL.ASAX.VB
HomeController.vb
Actually, something like this worked well
edit: ReadToByteArray method just makes a byte array from the stream