[英]send raw empty json with GuzzleHttp in laravel
My solution my be simple but honestly spent almost 5 hour and still not found my answer. 我的解决方法很简单,但老实说花费了将近5个小时,但仍然找不到我的答案。 I need Send request with
Post
and retrieve my data. 我需要发送带有
Post
请求并检索我的数据。 With POSTMAN it's work just fine. 使用POSTMAN,一切正常。
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 {}
. 使用
POSTMAN
,我不需要设置Header
,也不需要发送{}
。
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? 好吧,我现在该怎么办?
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' 看起来您想发送不带
application/x-www-form-urlencoded
POST数据,这是通过使用“ 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' => '{}'
]);
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.. 不确定如何传递对象,我想您可以根据需要传递带有数据的PHP对象作为第二个参数或对象数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.