最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

rest api - WP API file_get_contents return TTP request failed! HTTP1.1 401 Unauthorized

programmeradmin2浏览0评论

I've made this function to get the post id from WP Api , and Render it from server ( not by Js or Ajax ).

function api_featured_item_id($url) {

    $data = file_get_contents($url); // put the contents of the file into a variable
    $posts = json_decode($data,true); // decode the JSON feed

    $i = 0;
    $outuput = '';

    foreach( $posts as $item ) {
        $outuput .= $item['id'] .',';
        $i++;
        if($i==4) break;
    }

    return $outuput;
}

In local it work, after moving online, i've this error :

Warning: file_get_contents(): failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized in /home/public_html/website/wp-content/mu-plugins/general-functions.php

If I try to open the url on browser, work fine and I can see the Json Data correctly. I've set via PHP Ini the allow_url_fopen "enabled" , but not work.

发布评论

评论列表(0)

  1. 暂无评论