Note that there are some explanatory texts on larger screens.

plurals
  1. POC# REST client sending data using POST
    primarykey
    data
    text
    <p>I'm trying to send a simple POST request to a REST web service and print the response (code is below, mostly taken from Yahoo! developer documentation and the MSDN code snippets provided with some of the documentation). I would expect the client to send:</p> <p>Request Method: POST (i.e. I expect $_SERVER['REQUEST_METHOD'] == 'POST' in PHP)<br> Data: foo=bar (i.e. $_POST['foo'] == 'bar' in PHP)</p> <p>However, it seems to be sending:</p> <p>Request Method: FOO=BARPOST<br> Data: (blank)</p> <p>I know the API works as I've tested it with clients written in Python and PHP, so I'm pretty sure it must be a problem with my C#. I'm not a .NET programmer by trade so would appreciate any comments/pointers on how to figure out what the problem is - I'm sure it's something trivial but I can't spot it myself.</p> <p>uri, user and password variables are set earlier in the code - they work fine with GET requests.</p> <pre><code>request = (HttpWebRequest) WebRequest.Create(uri); request.Credentials = new NetworkCredential(user, password); request.Method = WebRequestMethods.Http.Post; request.ContentType = "application/x-www-form-urlencoded"; string postData = "foo=bar"; request.ContentLength = postData.Length; StreamWriter postStream = new StreamWriter(request.GetRequestStream(), System.Text.Encoding.ASCII); postStream.Write(postData); postStream.Close(); response = (HttpWebResponse) request.GetResponse(); </code></pre> <p>The REST API is written in PHP, and the $_POST array is empty on the server when using the C# client.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload