I am trying to make a C# application that connects to a MySQL database through PHP. My PHP code is the following:
<?php
require_once(dirname(__FILE__).'/dbconnect.php');
if (isset($_GET['name']) && isset($_GET['number']))
{
//Get the POST variables
$mName = $_GET['name'];
$mNumber = $_GET['number'];
//Insert new contact into database
$sql = "INSERT INTO `products`(`name`) VALUES (\"" . $mName . "\")";
echo $sql;
//Execute query
$stmt = mysqli_query($con, $sql);
if (!$stmt)
{
echo 'Query Failed';
}
else
{
echo "Query Successful";
}
}
mysqli_close($con);
?>
In my C# application I use a WebClient and the method DownloadString to make a request.
Uri uri = new Uri("http://manoest.dk/UpdateValue.php?name=John&number=23");
WebClient client = new WebClient();
client.Headers.Add("Content-Type", "text/html; charset=iso-8859-1");
//client.Headers.Add("Accept", "text/plain");
client.Headers.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
var streng = client.DownloadString(uri);
I have tried many different things, but everytime I will get an 406 error (Not acceptable). I guess that the headers are the problem, but I have tried and can't see the problem.