简体   繁体   English

将卷曲转换为guzzle

[英]convert curl to guzzle

i have this perfectly working curl command: 我有这个完美的curl命令:

curl -i --data "site=walletgroove.com&placement=above&device=desktop&source=*&campaign=*&url=*&country=*&active=1" http://10.0.0.38/adserver/src/public/api/rule which i tried to execute with guzzle but for some reason i keep getting error from my code, an exception to be more accurate. curl -i --data "site=walletgroove.com&placement=above&device=desktop&source=*&campaign=*&url=*&country=*&active=1" http://10.0.0.38/adserver/src/public/api/rule其中我试图用guzzle执行,但由于某种原因我不断从我的代码中得到错误,更准确的例外。 this exception is thrown when params are not passed properly. 当params未正确传递时抛出此异常。 this is one of few tries i had: 这是我的几次尝试之一:

public function testApi_postRule()
{
    $client = new Client();

    $client->post('http://10.0.0.38/adserver/src/public/api/rule',[ 'query' => [
         'site' => 'walletgroove.com',
         'placement' => 'guzzle_unique_placement',
         'device' => 'desktop',
         'source' => 'guzzource',
         'campaign' => '*',
         'country' => '*',
         'url' => '*',
         'active' => '1'
        ]]);
    }

any idea what am i doing wrong here?? 知道我在这里做错了什么?

You are passing the query parameter, which appends a query string instead of sending in the request body. 您正在传递query参数,该参数附加查询字符串而不是在请求正文中发送。 For a POST request, you probably want to use form_params as shown in the documentation . 对于POST请求,你可能想使用form_params如图所示的文件

$client->post('http://10.0.0.38/adserver/src/public/api/rule', [
    'form_params' => [
        'site' => 'walletgroove.com',
        'placement' => 'guzzle_unique_placement',
        'device' => 'desktop',
        'source' => 'guzzource',
        'campaign' => '*',
        'country' => '*',
        'url' => '*',
        'active' => '1'
    ]
]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM