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
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 signatureThe code I'm using to send the data looks like this
Using the same client to get data works fine
Using OAuth I've managed to post the data to the API like this
Sending the array to the API this way works fine.
I'm using
guzzlehttp/oauth-subscriberfor all the oauth side.What am I doing wrong with Guzzle?
Thanks