1
I’m trying to send a C# data to PHP, but the example I find and all solutions simply result in the same error.
using System.Net;
using System.Collections.Specialized;
string valor = "1";
string urlAddress = "http://localhost:80/Untitled-1.php";
using (WebClient client = new WebClient())
{
NameValueCollection postData = new NameValueCollection()
{
{ "valor", valor}
};
client.UploadValues(urlAddress, postData);
}
PHP code to receive data:
<html>
<?php
$valor = $_POST["valor"];
echo $valor;
?>
Error in PHP:
Notice: Undefined index: value in C: xampp htdocs Untitled-1.php on line 4
It’s a very simple code, but it’s the basis of a larger program. Does anyone have any idea what it might be?
Good evening, It may be that your php is not giving permission for external reading... Try assigning this at the top of your file: <?php header('Access-Control-Allow-Origin:*'); ? > Questions, I’m available.
– Júlio Rossato
Try to give a var_dump($_POST), if you do not give any value, it may be that your application c# is having some problem.
– Vasconcelosx