【发布时间】:2019-05-19 03:34:27
【问题描述】:
我正在尝试在我的 laravel 站点中测试 API 发布调用,但我发现用户不存在,因为我认为有效负载/正文没有被传递
如果我在 Swagger 中手动测试(成功)使用 id 和 body 作为
{
"password": "passwordTest",
"email": "email@apitest.com"
}
然后url显示为http://ip.address/login/?id=0,curl为
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\"}"
在我的服务文件中,它应该匹配所有结构,但我将其转储到页面,但没有有效负载(正文)时出现错误
我错过了什么吗?
AuthService.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);
}
【问题讨论】:
-
//throws various exceptions你能发布你得到的异常吗?