$url='http://api.cruiseline.com/cruises/7-night-western-caribbean-ft-lauderdale-roundtrip-35052/detail';
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL,$url);
$result=curl_exec($ch);
curl_close($ch);
$result=json_decode($result);
var_dump($result);
以下是curl_getinfo()
的回复array(26) { ["url"]=> string(96) "http://api.cruiseline.com/cruises/7-night-western-caribbean-ft-lauderdale-roundtrip-35052/detail" ["content_type"]=> string(16) "application/json" ["http_code"]=> int(200) ["header_size"]=> int(511) ["request_size"]=> int(127) ["filetime"]=> int(-1) ["ssl_verify_result"]=> int(0) ["redirect_count"]=> int(0) ["total_time"]=> float(5.11) ["namelookup_time"]=> float(0.203) ["connect_time"]=> float(0.532) ["pretransfer_time"]=> float(0.532) ["size_upload"]=> float(0) ["size_download"]=> float(650744) ["speed_download"]=> float(127347) ["speed_upload"]=> float(0) ["download_content_length"]=> float(-1) ["upload_content_length"]=> float(0) ["starttransfer_time"]=> float(1.125) ["redirect_time"]=> float(0) ["certinfo"]=> array(0) { } ["primary_ip"]=> string(14) "75.101.141.196" ["primary_port"]=> int(80) ["local_ip"]=> string(13) "192.168.10.15" ["local_port"]=> int(59916) ["redirect_url"]=> string(0) "" }
上面的代码有时会发送完整的json数据,有时会将部分数据发送到$result
。当它发送不完整的数据时,json_decode
会返回null
。
服务器端没有问题。当我们在浏览器中打开http://api.cruiseline.com/cruises/7-night-western-caribbean-ft-lauderdale-roundtrip-35052/detail时,它会一直发送完整的响应。
请帮忙,让我知道问题是什么以及我如何解决这个问题。
答案 0 :(得分:5)
添加:
cURL
到Boolean. Default: true
设置。这使我的代码适合我。