Get和delete工作,但其他方法不工作:restful server by phill


get and delete working but other methods not working: restful server by phill

我正在尝试实现Phil Sturgeon的rest服务器和学习api密钥认证。我使用rest客户端和curl库,再次由Phil Sturgeon。程序可以很好地处理get和delete请求,但在尝试post和其他剩余方法时,它会抛出"未授权"响应。当我尝试使用摘要身份验证时(这里我使用chrome高级rest客户端进行测试),用户名和密码不匹配,浏览器总是显示登录表单。这是我的旋度测试仪

  function rest_client_example($id)
{ 
    $this->load->library('rest', array(
        'server' => 'http://localhost:81/restserver/index.php/api/example/',
        'http_user' => 'admin',
        'http_pass' => '1234',
        'http_auth' => 'digest', // or 'digest'

    ));
    $user = $this->rest->put('user', array('id' => $id, 'X-API-KEY' => 'aa72dfaa70d6aa6c2c8d26b82c08d26db979f2f0'), 'application/json');
    print_r($user);exit;
    echo $user->name;
}

我使用的是rest服务器包中包含的默认示例类

header中传递API密钥

function rest_client_example($id)
    { 
        $this->load->library('rest', array(
            'server' => 'http://localhost:81/restserver/index.php/api/example/',
            'http_user' => 'admin',
            'http_pass' => '1234',
            'http_auth' => 'digest', // or 'digest',
            'api_key' => 'aa72dfaa70d6aa6c2c8d26b82c08d26db979f2f0',
            'api_name' => 'X-API-KEY',

        ));
        $user = $this->rest->put('user', array('id' => $id), 'application/json');
        print_r($user);exit;
        echo $user->name;
    }