views:

1138

answers:

4

Hey Folks, I'm trying to POST data to an external url using HttpWebRequest, then i need to redirect the user to the external url where which i just POSTed my data, can this be achieved on the first place ?

+1  A: 

Well, the redirect should be fairly standard - just a regular ASP.NET redirect.

Re doing a POST; that is fine - but it would be even easier to just use WebClient:

    using (WebClient client = new WebClient())
    {
        client.UploadData(address, "POST", data);
    }

(other methods and overloads for different use-cases)

Marc Gravell
thanks you for proposing WebClient, will it perform redirect ?
HeoQue
You'd have to try, sorry. I don't know off the top of my head.
Marc Gravell
AllowAutoRedirect : http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.allowautoredirect(VS.80).aspx
HeoQue
A: 

Sure, that's quite possible.

Depending on what data you need to post, the System.Net.WebClient class might be simpler than the HttpWebRequest. It can upload strings and files with one method call.

David
A: 

Unless there is something that needs to be done on the server side you should probably do this from JS on the client side.

Just submit a form programtically using JS that will take care of both the posting and the redirect.

Sruly
A: 

The easiest way to do this would be just to set the form's action attribute:

<form method="post" action="url/to/post/data/to">
....
</form>

Then the data and the user will be sent to your URL without you having to do anything programmatically.

Ian Oxley