2

I want to post one or more values to a php file on a strato (the host) server on a https domain using a C# WPF desktop application. However, after several attempts with a test program nothing seems to work. The testing value is not posted to the server, the $_POST Array is empty, respectively. I do get an echoed answer from the server but its always 'Error' (See script below).

I did try this with several techniques as well:

  • Webclient / HttpClient
  • HttpWebRequest
  • Adjusting SecurityProtocolType
  • sending value as byte[]

and what not.

$_GET by the way works perfectly fine as I always get back the computed testing value from the php script. However, I would like to have a POST Request since I am sending user data to the server.

More precisely, I already have tried these solutions (and several similar ones):

Testing PHP Script:

$newnumber = 'Error';
if(isset($_POST['number']))
{
    $newnumber = $_POST['number']+1;
}
echo $newnumber;
//keeps on returning 'Error'

Latest attempt of C# code:

string resultString = null;
string _url = "https://myURL.com/test.php";

//ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11;

HttpClient client = new HttpClient();

var content = new FormUrlEncodedContent(new[] {
    new KeyValuePair<string,string>("number", "2"),
});

var response = await client.PostAsync(_url, content);

resultString = await response.Content.ReadAsStringAsync();

this._txt.Text = resultString;
johnny 5
  • 19,893
  • 50
  • 121
  • 195
laschnesol
  • 21
  • 1

0 Answers0