我正在尝试将文档插入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;
}