Redirigir la solicitud a otra URL

In my action I have Request property. I want to use this request to get response from another URL (from otro sitio web). ¿Es posible?

preguntado el 08 de noviembre de 11 a las 18:11

"I want to use this request to get response from another URL" - you mean another website or just another action content? -

what do you mean by response from other site? do you mean redirect or just get something from other site? -

Redirect current request to another website and get response by this request, of course. -

the redirection must be server side or you can have a proper redirect ? In the first case, I suggest you to perform manually the HTTP Get and write its response on your controller response, otherwise you can use a RedirectResult (url, permanent) in your action -

Is it possible to save form data and coockiens from existing Request in your solution? -

1 Respuestas

To request a external webpage from C# code and retrieve it as a string. You can use the following snippet of code:

    var request = WebRequest.Create("");
    var response = request.GetResponse();
    var responseStream = response.GetResponseStream();
    using(var reader = new StreamReader(responseStream))
        // Convert stream object to string
        string myWebPage = reader.ReadToEnd();
}catch(Exception e)
    // TODO: Handle error exception

This will return the HTML in the string variable myWebPage. Also you will need to include the following 2 libraries:

using System.Net;
using System.IO;

Of course you can manipulate the request URL dependant on a users input.

respondido 14 nov., 11:17

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.