WP-API / menus-endpoints

Feature plugin for Menu Endpoints
43 stars 12 forks source link

how call to api rest from same domain ? #39

Closed hdkcreative closed 4 years ago

hdkcreative commented 4 years ago

hi team !

i have my worpdress in a subfolder : mydomain.com/cms

i create another folder /test-api and inside i create a file: index.php

content of this file index.php :

<?php
$json = "http://mydomain/cms/wp-json/wp/v2/users";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$contents = curl_exec($ch);
curl_close($ch);
if (!$contents) {
    $error = error_get_last();
    echo $error['message'];
}
else
    $data = json_decode($contents, true);

var_dump("result : ",$data);
?>

when in the browser i try to access to : http://mydomain/test-api/index.php the result is NULL...

but if i try to get this same file /test-api/index.php from another domain, this work !

but not in the same domain . . .

please help me !

TimothyBJacobs commented 4 years ago

Hi @hdkcreative!

This is an issue tracker for developing a REST API for menus in WordPress. The best place for support questions is the WordPress forums or Stack Exchange.

Taking a quick look, I think null would be getting returned if $contents is not valid JSON. I'd var_dump( $contents ) to make sure it is what you expect. Perhaps you are hitting a wrong URL.