PHP cURL,帮助创建API调用脚本
我需要一些帮助来创建一个cURL片段来调用API 如蒙协助,将不胜感激 这是API调用PHP cURL,帮助创建API调用脚本,php,api,curl,Php,Api,Curl,我需要一些帮助来创建一个cURL片段来调用API 如蒙协助,将不胜感激 这是API调用 POST https://api.passes.com/v1/templates/names/Member%20Card/pass 显然,他们需要发送以下信息 ------------------------------330184f75e21 Content-Disposition: form-data; name="values"; filename="values.json" Content-Type
POST https://api.passes.com/v1/templates/names/Member%20Card/pass
显然,他们需要发送以下信息
------------------------------330184f75e21
Content-Disposition: form-data; name="values"; filename="values.json"
Content-Type: application/json
{
"firstName": "John",
"lastName": "Doe",
}
------------------------------330184f75e21
Content-Disposition: form-data; name="icon"; filename="icon.png"
Content-Type: application/octet-stream
imagedata
------------------------------330184f75e21
Content-Disposition: form-data; name="icon@2x"; filename="icon@2x.png"
Content-Type: application/octet-stream
imagedata
我一点也不知道卷发里该放什么
我试过下列方法,但没有成功
$url1 = 'https://api.passes.com/v1/templates/names/Test/pass';
$data1 = array("values" => '{"first":"John","last":"Doe"}','application/json',
"strip" => '@../uploads/icon.png','application/octet-string','icon.png',
"strip@2x" => '@../uploads/icon.png','application/octet-string','icon.png');
$auth1 = array( "authorization: Basic xxxxxxxxxxxx=", "cache-control: no-cache", "postman-token: xxxxxxxxx");
$ch1 = curl_init($url1);
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch1, CURLOPT_POST, 1);
curl_setopt($ch1, CURLOPT_POSTFIELDS, $data1);
curl_setopt($ch1, CURLOPT_HEADER, 0);
curl_setopt($ch1, CURLOPT_HTTPHEADER, $auth1);
$response1 = curl_exec($ch1);
echo $response1;
它的响应是无效的JSON
如果有人能帮忙,那就太好了
谢谢
Rob您不应该编写原始json字符串,而是让PHP为您编写
$values = array(
'first' => 'John',
'last' => 'Doe'
);
$data1 = array(
'values' => json_encode($values),
'strip' => '@../uploads/icon.png',
'application/octet-string',
'icon.png',
'strip@2x' => '@../uploads/icon.png',
'application/octet-string',
'icon.png'
);
您不应该编写原始json字符串,而是让PHP为您编写
$values = array(
'first' => 'John',
'last' => 'Doe'
);
$data1 = array(
'values' => json_encode($values),
'strip' => '@../uploads/icon.png',
'application/octet-string',
'icon.png',
'strip@2x' => '@../uploads/icon.png',
'application/octet-string',
'icon.png'
);
好的,这意味着你发送的是有效的JSON格式,但是他们期望的数据结构无效。好的,这意味着你发送的是有效的JSON格式,但是他们期望的数据结构无效。