将数据发布到php

I ran into a problem lately:

C# code:

string URI = "http://cannonrush.tk/UpdateLogFile.php";
string myParameters = "text=test123";

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

PHP file:

<?php
if (isset($_GET['text'])) {
    $file = "LogFile.txt";
    $handle = fopen($file, 'a') or die('ERROR: Cannot write to file: ' . $file);
    date_default_timezone_set('Europe/Amsterdam');
    $data = '~ ' . date('l jS \of F Y h:i:s A') . '>> ' . $_GET['text'] . "

";
    fwrite($handle, $data);
    fclose($handle);
    echo "SUCCESS";
} else {
    echo "ERROR: Access forbidden without text";
}
?>

Now, whenever I run the above C# code, I get this output printed:

ERROR: Access forbidden without text

I have tried numerous versions to post data from C# to php, but nothing seems to work.

Any ideas?

Change $_GET["text"] to $_POST["text"] in the php file, or use DownloadString() instead of UploadString() in your C# code.

$_GET is only populated in GET requests, so UploadString will not work:

Uploads the specified string to the specified resource, using the POST method.

If you want to allow either verb, use $_REQUEST instead.