1

I've taken a simple example of the httpClient as per this answer https://stackoverflow.com/a/19983672

I'm trying to get this working, but on my server side (I'm logging the requests) it's empty.

c#

    async public void postTest(string theAddress)
    {
        HttpClient httpClient = new HttpClient();
        MultipartFormDataContent form = new MultipartFormDataContent();

        form.Add(new StringContent("abc"), "test");
        HttpResponseMessage response = await httpClient.PostAsync(theAddress, form);

        response.EnsureSuccessStatusCode();
        httpClient.Dispose();
        string sd = response.Content.ReadAsStringAsync().Result;
    }

And on the server side, I'm logging like this

php

    $log=''; 
    $log .= $_SERVER['REQUEST_METHOD']."\n";
    $log .= "Request array \n";
    $log .= print_r($_REQUEST,true);
    $log .= "Post array \n";
    $log .= print_r($_POST,true);

    $fp= fopen('log.txt', 'a+');
    fwrite($fp, $log."\n\n");
    fclose($fp);

My log after running the c# app looks like this

GET
Request array 
Array
(
)
Post array 
Array
(
)
Community
  • 1
  • 1
chip
  • 599
  • 1
  • 9
  • 20

1 Answers1

0

This turned out to be something rather stupid. I decided to open up fiddler (forgot about this lovely tool) and check the request.

The issue was that I was posting to a non www. address and the web server was setup to do a 301 redirect to the www. equivalent. The post was request was lost as the redirect was GET.

chip
  • 599
  • 1
  • 9
  • 20