[英]Error getting a json response from http request
我正在嘗試從Hunter API的http請求中獲取響應。
網址是這樣的:
https://api.hunter.io/v2/email-finder?domain=mydomain&api_key=myapikey&first_name=myfirstname&last_name=myname
響應是這樣的:
{
"data": {
"email": "emailfound@domain.tld",
"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服務器上進行性能測試。
您知道此回應來自何處嗎? 為什么我沒有得到真正的回應? 謝謝 !
根據我的評論,
而不是使用CURL(這是一個更難處理IMO的系統),應使用file_get_contents()
像這樣:
$json = file_get_contents($url);
$obj = json_decode($json,true);
嘗試這個:
$json = file_get_contents('https://api.hunter.io/v2/email-finder?domain=mydomain&api_key=myapikey&first_name=myfirstname&last_name=myname');
$data = json_encode($json,true)
var_dump($data);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.