How to programmatically request a URL in ASP.NET?

I would like the server to call the URL (ashx page) programmatically and save the response as a string. Using HttpWebRequest does not seem to work properly, because I do not want to redirect the client there.

Thanks.

+3
source share
6 answers

If you want to call another page and return the response as a string, you can use a class WebClient.

var myWebClient = new WebClient();
string resultStr = myWebClient.DownloadString("http://www.google.com");
+13
source

First, you need to determine what you mean by “calling”:

  • Should the user's browser go to a specific URL? use Response.Redirect ()

  • ASP.Net URL-? iframe

  • , URL- ? WebRequest.Create(), , IIS .

, HttpWebRequest "" . ?

+2

ashx Response.Redirect:

System.Web.HttpContext.Current.Response.Redirect("http://www.stackoverflow.com/");

System.Web.HttpContext.Current.Server.Transfer("a path to a page on the same server");

:

  • Response.Redirect
  • Server.Trasfer
  • Postbackurl
+1

. HttpWebRequest WebClient.

+1

Response.Redirect( "SomeURL" );

0

You can use a socket. But that sounds crazy. You can use the XMLHttpRequest object, you know MSXML2.XMLHttpRequest, but this is crazy again. What do you mean by the "does not send byte information" part ...

0
source

Source: https://habr.com/ru/post/1715649/


All Articles