简体   繁体   中英

Guzzle - How to check query string?

I am attempting to use Guzzle (6) with Laravel (5.4) to make a GET request, but the API I am connecting too keeps coming back that I may not have entered the correct parameter and/or parameter values.

<?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>

As far as I can see from my code, everything that is needed is there, but is there a way to see what URL Guzzle has built using the base and query string?

Below is my code:

$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);

I've tested the URL and query string using Postman and it works fine, so it must be either Guzzle not building the query string, or building it incorrectly.

Help on this one would be great.

You can get the full request debug information simply by setting the debug parameter to true in the ->request() method call.

client->request('GET', 'Attachments/getRelatedRecords', [
  'query' => $query,
  'debug' => true
]);

Source : http://docs.guzzlephp.org/en/stable/request-options.html#debug

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM