当我使用GuzzleHttp\Client
工作正常,但form_params
没有工作,但它和我一起工作的另一个项目,但这个项目没有PARAMS和我一起工作,当我在form_params
发送
狂饮代码工作
$http = new Client;
try {
$response = $http->post('https://smsmisr.com/api/webapi/?username='.$this->username.'&password='.$this->password.'&language=1&sender='.$this->sender.'&mobile=XXXX&message=Hello&DelayUntil='.Carbon::now()->toDateTimeString());
// retrun json_decode((string)) $response->getBody(), true);
return $response->getBody();
} catch (\GuzzleHttp\Exception\BadResponseException $e) {
if($e->getCode() === 400) {
return response()->json('Invalid Request.', $e->getCode());
} else if ($e->getCode() === 401) {
return response()->json('Your username and passowrd are incorrect', $e->getCode());
}
return response()->json('Something went wrong on the server', $e->getCode());
}
狂饮代码不工作的代码没有任何发送尚未form_params。
$response = $http->post($this->link, [
'headers' => [
'User-Agent' => 'testing/1.0',
'Accept' => 'application/json',
'X-Foo' => ['Bar', 'Baz']
],
'form_params' => [
'username' => $this->username,
'password' => $this->password,
'sender' => $this->sender,
'language' => 1,
'mobile' => 'XXXXXXX',
'message' => 'Hello guys',
'DelayUntil' => Carbon::now()->toDateString()
]
]);
这个问题在我的Vuejs太爱可信使用时,我应该让小号
ubmitForm(context, data) {
const params = {
...data
}
return new Promise((resolve, reject) => {
axios.post(`${data.post.apiURL}`, params)
.then(response => {
resolve(response)
})
.catch(error => {
reject(error)
})
})
},
我在邮递员测试。
从文档here
form_params
不能json
使用:
form_params不能与多选项一起使用。您将需要使用一个或另一个。使用form_params应用/的X WWW的形式,进行了urlencoded请求,并为多的multipart / form-data的请求。
此选项不能与身体,多,或JSON使用
试试这个兄弟,变“form_params”到“JSON”
$response = $http->post($this->link, [
'headers' => [
'User-Agent' => 'testing/1.0',
'Accept' => 'application/json',
'X-Foo' => ['Bar', 'Baz']
],
'json' => [
'username' => $this->username,
'password' => $this->password,
'sender' => $this->sender,
'language' => 1,
'mobile' => 'XXXXXXX',
'message' => 'Hello guys',
'DelayUntil' => Carbon::now()->toDateString()
] ]);