我试图将Guzzle(6)与Laravel(5.4)一起发出GET请求,但是我连接的API也不断回来,我可能没有输入正确的参数和/或参数值。
<?xml version="1.0" encoding="UTF-8" ?>
<response uri="/crm/private/Attachments/getRelatedRecords">
<error>
<code>4600</code>
<message>Unable to process your request. Please verify whether you have entered proper method name,parameter and parameter values.</message>
</error>
</response>
从我的代码中可以看出,所需的一切都在那里,但有没有办法看到Guzzle使用基本和查询字符串构建的URL?
以下是我的代码:
$query = array( 'parentModule' => 'Attachments',
'id' => 6518161681681,
'authtoken' => "g8h98sdfhksdjh88sdxcb",
'scope' => "crmapi",
'newFormat' => 1
);
$response = $client->request('GET', 'Attachments/getRelatedRecords', [
'query' => $query
]);
$code = $response->getStatusCode();
$body = $response->getBody();
var_dump((string)$body);
我已经使用Postman测试了URL和查询字符串,它工作正常,因此它必须是Guzzle不构建查询字符串,或者构建错误。
这方面的帮助会很棒。
答案 0 :(得分:1)
只需在debug
方法调用中将->request()
参数设置为true即可获得完整的请求调试信息。
client->request('GET', 'Attachments/getRelatedRecords', [
'query' => $query,
'debug' => true
]);
来源:http://docs.guzzlephp.org/en/stable/request-options.html#debug