Php GuzzleHttp中带参数的Laravel问题 你好

Php GuzzleHttp中带参数的Laravel问题 你好,php,laravel,vue.js,guzzle,guzzlehttp,Php,Laravel,Vue.js,Guzzle,Guzzlehttp,当我使用guzzle时,http\Client工作正常,但form\u params不工作,但它在另一个项目中与我一起工作,但当我将其发送到form\u params 狂饮代码工作 $http = new Client; try { $response = $http->post('https://smsmisr.com/api/webapi/?username='.$this->

当我使用
guzzle时,http\Client
工作正常,但
form\u params
不工作,但它在另一个项目中与我一起工作,但当我将其发送到
form\u 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());
                        }
狂饮代码不工作 代码尚未发送任何表单参数

$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()
    ]
]);
使用Axios时,我的Vuejs中也存在这个问题,我应该

我在邮递员身上做测试。

来自文件

form_params
不能与
json
一起使用:

form_参数不能与multipart选项一起使用。您需要使用其中一个。对于应用程序/x-www-form-urlencoded请求,使用form_参数;对于多部分/表单数据请求,使用multipart参数

此选项不能与body、multipart或json一起使用

从文件中

form_params
不能与
json
一起使用:

form_参数不能与multipart选项一起使用。您需要使用其中一个。对于应用程序/x-www-form-urlencoded请求,使用form_参数;对于多部分/表单数据请求,使用multipart参数

此选项不能与body、multipart或json一起使用

试试这个兄弟,把“form_params”改成“json”

试试这个兄弟,把“form_params”改成“json”


您是否尝试过使用
json
而不是
form_params
,如前所述?不久前在使用
form_params
时遇到这个问题,它与
json
一起工作。如果你能发布你得到的实际错误(如果有的话)也会有帮助。这是给我同样的错误
'json'=>['username'=>this->username,'password'=>this->password,'sender'=>this->sender,'language'=>1,'mobile'=>XXXXX,'message'=>'大家好','DelayUntil'=>Carbon::now()->toDateString()]
您遇到了什么错误?{“code”:“8001”}它的意思是mobile是null Idk,但是当在URL中发送mobile时,它给我的用户名是null too你是否尝试过使用
json
而不是
form\u params
,如前所述?不久前在使用
form\u params
时遇到了这个问题,它与
json
一起工作。如果你能发布实际的错误,也会有所帮助你得到了(如果有的话)。它会给我同样的错误
'json'=>['username'=>this->username,'password'=>this->password,'sender'=>this->sender,'language'=>1,'mobile'=>XXXXX,'message'=>'大家好','DelayUntil'=>Carbon::now()->toDateString()]
您得到的错误是什么?{“code”:“8001”}它的意思是手机是空的Idk,但是当在URL中发送手机时,它给我的用户名是空的,那么我可以使用什么?然后我可以使用什么?
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)
                    })
            })
        },
    $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()
] ]);