Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将PHP中的POST请求与FullContactAPI一起用于批处理请求?_Php_Post_Fullcontact - Fatal编程技术网

如何将PHP中的POST请求与FullContactAPI一起用于批处理请求?

如何将PHP中的POST请求与FullContactAPI一起用于批处理请求?,php,post,fullcontact,Php,Post,Fullcontact,我无法从fullcontact API批量请求数据。收到的响应为“无效查询对象”,代码如下: $urltopost = "https://api.fullcontact.com/v2/batch.json?apiKey=xxxxxxxxxx"; $datatopost = array ( "requests" => '["https://api.fullcontact.com/v2/person.json?email=bart@fullcontact.com","htps://ap

我无法从fullcontact API批量请求数据。收到的响应为“无效查询对象”,代码如下:

$urltopost = "https://api.fullcontact.com/v2/batch.json?apiKey=xxxxxxxxxx";
$datatopost = array (
    "requests" => '["https://api.fullcontact.com/v2/person.json?email=bart@fullcontact.com","htps://api.fullcontact.com/v2/person.json?email=jigarbhatt30893@yahoo.co.in"]'
);
$header=array("content-type"=>"application/json");
$ch = curl_init ($urltopost);
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $datatopost);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_HTTPHEADER, $header);
$returndata = curl_exec ($ch);
print_r($returndata);
编写正确运行的shell执行

curl --request POST "https://api.fullcontact.com/v2/batch.json?apiKey=xxxxxxxxxx" --data '{'requests':["https://api.fullcontact.com/v2/person.json?email=bart@fullcontact.com","https://api.fullcontact.com/v2/person.json?email=jigarbhatt30893@yahoo.co.in"]}' --header 'content-type:application/json'

但我不想从php调用shell_exec来实现这一点。我想让cURL函数工作。出什么问题了?

能否尝试从请求数组中删除单引号

"requests" => ["https://api.fullcontact.com/v2/person.json?email=bart@fullcontact.com","htps://api.fullcontact.com/v2/person.json?email=jigarbhatt30893@yahoo.co.in"]

嗯。所以我想我找到了自己的答案。我只需将该数组更改为字符串。它工作得很好

$datatopost = '{"requests":["https://api.fullcontact.com/v2/person.json?email=bart@fullcontact.com","https://api.fullcontact.com/v2/person.json?email=jigarbhatt30893@yahoo.co.in"]}';

试试这个,我已经测试过了,效果很好。不需要在post方法中发送数据

$urltopost = "https://api.fullcontact.com/v2/person.json?apiKey=xxxxxxxxxx&email=someone@xyz.com&method=email";

$header=array("content-type"=>"application/json");
$ch = curl_init ($urltopost);
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_HTTPHEADER, $header);
$returndata = curl_exec ($ch);
print_r($returndata);

谢谢Danny的编辑帮助。我在这个问题上陷入了一段时间。下面是一个链接,其中提供了一个Post请求的示例。