Skip to content

Guzzle 401 response sending data by post #31

@Fynkymynky

Description

@Fynkymynky

I've been using Guzzle to get data from my API, but when I try and post data to the API I get the following error:

Fatal error: Uncaught exception 'GuzzleHttp\Exception\ClientException' with message 'Client error response [url] http://www.mywebsite.bar/rest/v4/foo/ [status code] 401 [reason phrase] Unauthorized : Invalid signature

The code I'm using to send the data looks like this

$request = $this->client->post('http://www.mywebsite.bar/rest/v4/foo/' ,
  array('Content-Type: application/x-www-form-urlencoded'),
  array());
$request->setBody($my_data); #set body!
$response = $request->send();

return $response;

Using the same client to get data works fine

$res = $this->client->get( $url);
return $res->getBody();

Using OAuth I've managed to post the data to the API like this

$my_data['name'] = 'Bob';
$my_data['age'] = 34;
$my_data['location[home]'] = 'foo';
$my_data['location[work]'] = 'bar';

$oauth->fetch( $url , $my_data , OAUTH_HTTP_METHOD_POST );

Sending the array to the API this way works fine.

I'm using guzzlehttp/oauth-subscriber for all the oauth side.

What am I doing wrong with Guzzle?

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions