Is there a way to, from server-side code in C#, send an HTTP Request and gather the result? What I want to do is this:
- HTTPRequest sent from client browser to page
- Server-Side C# code does some boolean checking
- If checking pans out, send and HTTPRequest to another page
- Get HTTPResponse and populate to innerHTML of a div
- Send itself’s HTTPResponse to the client browser for viewing
Is this possible?
You can use the same libraries which you’d use on a “normal” (i.e., client) application on the server side as well.
HttpWebRequest,WebClient, etc., they should work just fine.One note, though: if you make synchronous requests (
HttpWebRequest.GetResponse,WebClient.DownloadData, etc.), those requests will block the server thread, so if you need to scale the server to serve a large number of clients this may become a problem. If that happens, you can consider making your operation asynchronous. But you shouldn’t do it unless you have a (current or foreseeable) problem.