Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从unity发送请求时,文件\u get\u内容返回null_C#_Php - Fatal编程技术网

C# 从unity发送请求时,文件\u get\u内容返回null

C# 从unity发送请求时,文件\u get\u内容返回null,c#,php,C#,Php,我正在用PHP处理post请求数据: header("Access-Control-Allow-Origin: *"); header("Content-Type: application/json; charset=UTF-8"); header("Access-Control-Allow-Methods: POST"); header("Access-Control-Max-Age: 3600"); header("Access-Control-Allow-Headers: Content-

我正在用PHP处理post请求数据:

header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Methods: POST");
header("Access-Control-Max-Age: 3600");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");


    $data = json_decode(file_get_contents("php://input"));

    print $data;

    if(empty($data)){
        echo "\n data is empty";
    }
以及从C#发送数据:


但是在服务器端,我得到了一个错误,
$data
对于每个遇到这个问题的人来说都是空的:

从我们的谈话中
unity
urlencoded
的形式发送请求。发送URL编码数据:

  • uri
    表单数据将传输到的目标uri

  • postData
    表单正文数据。将在传输之前进行URL编码

  • PHP
    中解码数据

    $request = file_get_contents("php://input");
    $decoded = urldecode($request);
    
    要将json解析为对象:

    $data = json_decode($decoded);
    
    获取json的属性

    $data->{attribute};
    

    检查
    文件获取内容的结果(“php://input)
    。可能您的请求不是json。如何检查它?put
    var\u dump(file\u get\u contents(“php://input"));
    $data=..
    行之前是的,当执行来自C的请求时它是空的,但在POSTMANso中它是正确的,我认为您的请求没有被放入。试试这个
    var\u转储($\u POST)。如果此请求为空,则必须检查客户端。
    
    $data->{attribute};