与Emarsys的Guzzle Api连接

时间:2018-09-04 06:14:08

标签: api guzzle

我试图像这样用枪g从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错误请求。

1 个答案:

答案 0 :(得分: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,
        ],
    ]);