Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP POST - I'm stuck

Tags:

I have to POST some parameters to a URL outside my network, and the developers on the other side asked me to not use HTTP Parameters: instead I have to post my key-values in HTTP Headers.

The fact is that I don't really understand what they mean: I tried to use a ajax-like post, with XmlHttp objects, and also I tried to write in the header with something like

Request.Headers.Add(key,value);

but I cannot (exception from the framework); I tried the other way around, using the Response object like

Response.AppendHeader("key", "value");

and then redirect to the page... but this doesn't work, as well.

It's evident, I think, that I'm stuck there, any help?


EDIT I forgot to tell you that my environment is .Net 2.0, c#, on Win server 2003. The exception I got is

System.PlatformNotSupportedException was unhandled by user code
  Message="Operation is not supported on this platform."
  Source="System.Web"

This looks like it's caused by my tentative to Request.Add, MS an year ago published some security fixes that don't permit this.

like image 833
ila Avatar asked Sep 02 '08 20:09

ila


2 Answers

Have you tried the WebClient class? An example might look like:

        WebClient client = new WebClient();
        NameValueCollection data = new NameValueCollection();
        data["var1"] = "var1";
        client.UploadValues("http://somewhere.com/api", "POST", data);
like image 137
Ryan Duffield Avatar answered Sep 30 '22 17:09

Ryan Duffield


Like @lassevk said, a redirect won't work.

You should use the WebRequest class to do an HTTP POST from your page or application. There's an example here.

like image 36
John Rutherford Avatar answered Sep 30 '22 18:09

John Rutherford