1

I want to post variables from C# to a php-script on my webserver. I tried this following code from the internet but it returns this error message: Error: The remote server returned an error. (406) Not Acceptable.

The c# part:

string URI = "https://myserver.com/post.php";
            string myParameters = "param1=value1&param2=value2";

            using (WebClient wc = new WebClient())
            {
                wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
                string HtmlResult = wc.UploadString(URI, myParameters);
                MessageBox.Show(HtmlResult);
            }

The php part:

<?php
    if(isset($_POST['param1']) && isset($_POST['param2']))
    {
        $user = $_POST['param1'];
        $date = $_POST['param2'];

        echo $user . ' : ' . $date;
    }

?>

I have tested it with a test post server and it works but it won't work on my server.

1 Answers1

0

Your backend service is saying that the response type it is returning is not provided in the Accept HTTP header in your Client request.

Source: What is "406-Not Acceptable Response" in HTTP?

Community
  • 1
  • 1
Subtixx
  • 16
  • 1
  • 1
  • 3