Guzzle Api连接到Emarsys

问题描述 投票:0回答:1

我尝试用像这样的guzzle来获取emarsys的contactdata

$client = new Client([
        'base_uri' => 'www.ApiUrl.com',
    ]);

    $request = $client->request($requestType, $endPoint, [
        'query'   => $sQuery,
        'debug'   => true,
        'body'    => $sPostFields,
        'headers' => [
            'Content-type: application/json;charset="utf-8"',
        ],
    ]);

我总是得到400 Bad Request。

api guzzle
1个回答
0
投票

试试这种方式:

use GuzzleHttp\Client;

   $client  = new \GuzzleHttp\Client(); 
    $response = $client->request('POST','www.ApiUrl.com',[
        'headers' => [
            'content-type' => 'application/x-www-form-urlencoded'
        ],
        'form_params' => [
            'name'=>$name,
            'to' =>$email,
        ],
    ]); 
© www.soinside.com 2019 - 2024. All rights reserved.