我试图从来自Hunter API的http请求获取响应。从http请求获取json响应时出错
的URL是这样的:
https://api.hunter.io/v2/email-finder?domain=mydomain&api_key=myapikey&first_name=myfirstname&last_name=myname
和响应是这样的:
{
"data": {
"email": "[email protected]",
"score": 68,
"domain": "domain.tld",
"sources": [
{
"domain": "domain.tld",
"uri": "http://somedomain.tld/",
"extracted_on": "2017-04-04"
}
]
},
"meta": {
"params": {
"first_name": "myfirstname",
"last_name": "mylastname",
"full_name": null,
"domain": "domain.tld",
"company": null
}
}
}
下面是我在做什么在我的控制器:
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
curl_close($curl);
// return response
$json = new JsonResponse();
$datas = $json->setData($response);
return json_encode($datas);
以下是json_encode($ datas)返回的内容:
{"headers":{}}
我确切地说我正在使用Symfony3并在我的OVH服务器(Performance offer)上进行测试。
任何想法都来自这个回应?为什么我没有得到真正的回应?谢谢 !
你必须使用卷曲吗?你可以通过$ json = file_get_contents($ url)获得api结果;'从我的经验 – GrumpyCrouton
中获得完美的效果!这么简单,谢谢! – Melody
如果有人帮助了您,您应该点击答案左边的复选标记将答案标记为“正确”:) – GrumpyCrouton