我正在尝试学习cURL以使用JSON Web服务。我在线尝试了几个教程,但似乎都没有帮助。
我想访问此网址:https://uat.petfirsthealthcare.com/pfh.service.webservices/coreservice.svc/json/GetColorList 并返回结果以用于另一个调用。但是当我尝试时,我没有得到任何回报。
我用过这个:
$request = 'https://uat.petfirsthealthcare.com/pfh.service.webservices/coreservice.svc/json/GetColorList';
curl_init($request);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$response = curl_exe($session);
curl_close($session);
echo $response;
当你转到URL时,它返回JSON就好了。感谢您提供的任何帮助!
答案 0 :(得分:2)
TESTED 和 WORKS !
<?php
$request = 'https://uat.petfirsthealthcare.com/pfh.service.webservices/coreservice.svc/json/GetColorList';
$session = curl_init();
curl_setopt($session, CURLOPT_URL, $request);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_SSLVERSION,3);
curl_setopt($session, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($session, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($session, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($session, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
$response = curl_exec($session);
curl_close($session);
var_dump($response);
答案 1 :(得分:1)
$session
?$session = curl_init($request);
这里有一个错字:
$response = curl_exec($session);
答案 2 :(得分:0)
我可以看到两个问题:
$session
curl_exec()
,而不是 curl_exe 更新代码
<?php
$request = 'https://uat.petfirsthealthcare.com/pfh.service.webservices/coreservice.svc/json/GetColorList';
$session = curl_init($request);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($session);
curl_close($session);
echo $response;