简体   繁体   中英

curl doesnt work and i didnt get any result

I wrote this code and I didn't get any results.

What's wrong?

$agent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)';
$url="http://www.aliexpress.com/item/2014-Winter-Carters-Newborn-Clothes-Baby-Boy-Polar-Fleece-Fabric-Romper-Long-sleeve-Baby-Costume-Baby/32255697345.html?spm=2114.031010208.3.1.uspHz6&ws_ab_test=searchweb201556_3,searchweb201644_4_10001_10002_10005_301_10006_10003_10004_62_61,searchweb201560_8,searchweb1451318400_6149";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
$html=curl_exec($ch);
curl_close($ch);
$html = curl_exec($ch);
$info = curl_getinfo($ch); // Add this line to your code and print

Part of printed result from $info:

 ["http_code"]=>int(302) // This code say you need load url from "redirect_url" (if not empty)
 .................
 ["redirect_url"]=>string(314) "........." // You need go to this url (try curl with this address)

Note: if "redirect_url" will empty, but you don't receive page content, you'll need enable headers for curl-query, extract url from header Location and use it like next address for curl. ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM