Reputation: 2323
My solution my be simple but honestly spent almost 5 hour and still not found my answer.
I need Send request with Post
and retrieve my data.
With POSTMAN it's work just fine.
and here my Code
use GuzzleHttp\Client;
$client =new Client();
$client->post($url,[
'form_params' => [
'{}'
]
]);
with POSTMAN
, I don't need to set Header
and all i need to send {}
.
Get this Error :
Client error: `POST http://URL` resulted in a `400
Bad Request` response: {"error":"Failed when parsing body as json"}
Well,How Can I do it now?
Upvotes: 1
Views: 2704
Reputation: 3312
It looks like you want to send your POST data without application/x-www-form-urlencoded
which is what automatically added by using 'form_params'
If you wish to do this, you should do something more akin to the following:
use GuzzleHttp\Client;
$client = new Client();
$response = $client->post($url, [
'body' => '{}'
]);
Upvotes: 3
Reputation: 1
I think you can just do
$client->post($url,[
'parameter_one' => $value1,
'param_two' => $value2,
]);
Not sure about how to pass object, i think you can pass PHP object with data as second parameter or array of objects, if you wish..
Upvotes: 0