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'] . "\n\n";
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?