I would like the server to call a URL (an ashx page) programmatically and store the response as a string. Using HttpWebRequest doesn't seem like it will work properly because I do not want to redirect the client there.
Thanks.
I would like the server to call a URL (an ashx page) programmatically and store the response as a string. Using HttpWebRequest doesn't seem like it will work properly because I do not want to redirect the client there.
Thanks.
Inside the ashx you should use Response.Redirect:
System.Web.HttpContext.Current.Response.Redirect("http://www.stackoverflow.com/");
or:
System.Web.HttpContext.Current.Server.Transfer("a path to a page on the same server");
At your page you can do a:
First, you need to define what you mean by "call":
Should the user's browser navigate to a specific URL? use Response.Redirect()
Should the output of your ASP.Net page include the contents of another URL? Use an iframe
Do you want your code to retrieve the contents of another URL and process it? Use WebRequest.Create(), but be aware that the request is issues by the IIS user by default.
I thought HttpWebRequest was the "easy" way, though. What's so bad about it?
There is no way to receive a response without sending a request. Use HttpWebRequest, or the simplified WebClient class.
You may wanna use a socket. Buts thats sounds insane. You can use the XMLHttpRequest object, you know MSXML2.XMLHttpRequest, buts thats insane again. Wht do u mean by the "not sending byte info" part...
If I understood you want to call another page and get the response back as string, if so, you can use WebClient class.
Exemple:
var myWebClient = new WebClient();
string resultStr = myWebCliente.DownloadString("http://www.google.com");