• Good evening.

    I need some assistance if possible.

    I have a script that asks for an url file, which is read with wp_remote_get

    I’m trying to make that url point to a php file and return a json response as if it was a file.

    So far, I was able to do it like this: I created an array, and after that I coded:

    header("Content-type:application/json"); 
    $out = json_encode($json, true); 
    echo $out; 

    where $json was a php array. The problem is that it’s not working anymore – it was, but not now.

    Any ideas please?

    Kind regards

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Sending a proper Content-type header should be all that’s required, though I’ve heard IE has some issues with “application/json” MIME type. It supposedly can be fixed with a registry entry.

    If this was once working and you’ve made no changes, the problem likely lies elsewhere. Does requesting a static JSON file work correctly? You can try comparing the server response of a static file with that of the PHP file, maybe there’s something missing that’s critical for the requesting script. For example, a static file request will likely include caching data which are missing with a PHP request. If the script needs such information, you’d need to program the PHP response to include such data. Data like last-modified and etag.

Viewing 1 replies (of 1 total)
  • The topic ‘Json file response’ is closed to new replies.