我现在真的很沮丧,我需要更有经验的口香糖专家的帮助。
如果我想要一个来自API服务器的代码消息响应,而不是一个完整的链接响应,我将连接到一个API,它需要一个布尔值。
下面是由原始http客户端(Postman)访问的两种返回类型之间区别的示例:
启用布尔代码:
禁用布尔代码:
我遇到的问题是,当我使用get 6发出相同的请求时,我总是会得到完整的链接响应,并且永远无法在post正文中得到要应用的布尔值。看来布尔参数被压缩为“true”(这是我的猜测)。
因此,以下两个POST请求产生完全相同的结果:
// define request parameters
$this->req_body = [
'email' => $encrypted_email,
'code' => true
];
// request url
$request_url = $api_endpoint . self::RETURN_TYPE;
// instance of Guzzle Client
$client = $this
->client();
// abstract connection
// XXX: this request needs no headers
$response = $client
->post($request_url, array(
'form_params' => $this->req_body
));
// real data
$data = $response
->getBody()
->getContents();
// send output
$this->response = $data;
如果我尝试使用注释掉的code
表单参数:
// define request parameters
$this->req_body = [
'email' => $encrypted_email\\,
//'code' => true
];
// request url
$request_url = $api_endpoint . self::RETURN_TYPE;
// instance of Guzzle Client
$client = $this
->client();
// abstract connection
// XXX: this request needs no headers
$response = $client
->post($request_url, array(
'form_params' => $this->req_body
));
// real data
$data = $response
->getBody()
->getContents();
// send output
$this->response = $data;
返回的API响应总是:"{"success":{"code":200,"message":"https:\/\/webservices.bvdpetroleum.com\/users\/user-password-reset\/q8VqSAbfTOkW0EMvSTfK5qSS4zr28rSwdQy3D\/uc9wtz3+RI4LH7hDkh\/ZbTfqcC"}}"
如何在Boolean
6 form_params
数组中发送form_params
值?任何洞察力都会非常感谢,因为我不想切换到CURL
。
谢谢!
发布于 2016-09-01 18:39:04
只需更改form_params
数组以作为json
post正文发送:)
$response = $client->post($request_url, array(
'json' => $this->req_body
));
https://stackoverflow.com/questions/39277861
复制相似问题