我正在尝试在我的Laravel站点中测试一个API后调用,我发现用户不存在,因为我相信有效负载/主体不会被传递。
如果我在招摇过市时手动测试(成功),使用id和body作为
{
"password": "passwordTest",
"email": "email@apitest.com"
}
然后URL显示为
http://ip.address/login/?id=0
卷曲是
curl -X POST "http://ip.address/login/?id=0" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"password\": \"passwordTest\", \"email\": \"email@apitest.com\"}"
在我的服务文件中,它应该与所有构造匹配,但是我将其转储到页面,得到的错误没有有效负载(主体)。
我错过什么了吗?
AuthServices PHP
public function loginGetToken(){
$password = "passwordTest";
$email = "email@apitest.com";
$id = "0";
$payload = (object)[
'password'=>(string)$password,
'email'=>(string)$email
];
$retval = $this->post('http://ip.address/login/?id='.$id,$payload);
return $retval;
}
private function post($endpoint,$payload){
//throws various exceptions:
$result = $this->guzzleClient->request('POST', $endpoint, ['json'=>$payload]);
$body = $result->getBody();
return json_decode($body);
}