file_get_contents returning null when sending request from unity

后端 未结 1 631
孤独总比滥情好
孤独总比滥情好 2021-01-28 22:19

I am handling post request data in PHP:

header(\"Access-Control-Allow-Origin: *\");
header(\"Content-Type: application/json; charset=UTF-8\");
header(\"Access-Co         


        
1条回答
  •  不思量自难忘°
    2021-01-28 23:10

    For everyone who comes to this question:

    From conversation we had. unity sends request as urlencoded. The UnityWebRequest.Post send urlencoded data:

    1. uri The target URI to which form data will be transmitted.

    2. postData Form body data. Will be URLEncoded prior to transmission.

    to decode data in PHP.

    $request = file_get_contents("php://input");
    $decoded = urldecode($request);
    

    to parse json to object:

    $data = json_decode($decoded);
    

    to get attribute of json.

    $data->{attribute};
    

    0 讨论(0)
提交回复
热议问题