user3739757 user3739757 - 22 days ago 9
Android Question

PHP API Content-Type: application/json. Response empty data

Works fine for:


  • Sending from Android platform to PHP (web service)

  • Request headers sent with this
    Content-Type: application/x-www-form-urlencoded



Not working for:


  • Request headers sent with
    Content-Type: application/json
    . no data is received



API is working on same platform but not in cross platform:


  • Web to web WORKING

  • Android to web NOT WORKING



In PHP added both header on top:

header("Access-Control-Allow-Origin: *");
header('Content-Type: application/json');

Answer

after log search i found my answer.. we need this function to get $_POST response from cross platform (android to web)

file_get_contents('php://input')

OR we can also use this function to get $_POST response

$HTTP_RAW_POST_DATA

here is complete function to get the response.

$data = urldecode(file_get_contents('php://input'));
echo $data;