我試圖從來自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