使用cURL发送用户名和密码

时间:2016-11-07 22:45:34

标签: php curl

我正在尝试使用php cURL访问API。文档说:

  

每个请求必须包含分配给电子邮件的API密钥   伙伴。它应该是

     

通过标准的基本HTTP身份验证(如   在RFC2617中定义为

     

密码为空的用户名。

如何将API密钥作为用户名发送并将PW保留为空?以下是我到目前为止的情况:

$subscriberInfo = [
    'email' => $email,
    'search' => $jobType,
    'location' => $location
];

$ch = curl_init('https://api.ExternalSiteHere');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $subscriberInfo);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: multipart/form-data'
    ));

// execute!
$response = curl_exec($ch);

// close the connection
curl_close($ch);

var_dump($response);
die();

1 个答案:

答案 0 :(得分:3)

- name: associate an elastic IP with an instance ec2_eip: region: 'us-west-2' instance_id: "{{ ec2['tagged_instances'][0]['id'] }}" ip: "{{ elastic_ip }}"

在你的情况下

curl_setopt($ch, CURLOPT_USERNAME, base64_encode("{$username}:{$password}"));

如果不起作用,请在用户名

后删除冒号
相关问题