400 Bad Request`响应:错误:bad_request,原因:需要Referer标头

时间:2017-03-15 09:50:51

标签: php couchdb guzzle laravel-5.4

我正在尝试将文档插入couchdb中的数据库。 但我得到错误

客户端错误:POST http://localhost:5984/login/new_document导致400 Bad Request响应: {“error”:“bad_request”,“reason”:“需要Referer标题。”}

这是我的代码

public function guzzle_insert_doc()
{
    $client = new Client(); 

    $val=array(array(" _id " => " Raju ") , array(" age " => " 23 ") ,array(" Designation " => " Designer " ));     
    $val= json_encode($val);
    //echo $val;
    $res = $client->request('POST', 'http://localhost:5984/login/new_document',[
            'json' => $val 
        ]);
    $code = $res->getBody()->getContents();

    return $code;   
}

这是我尝试了另一种方式但仍然出现错误

public function guzzle_insert_doc()
{
    $client = new Client();     
    $res = $client->request('PUT', 'http://localhost:5984/login/new_doc',[
            "uname" => "admin",
            "password" => "admin123"  

        ]);


    //return $res;
}

0 个答案:

没有答案