I try to get html result from a site using cURL in PHP, and I got 301 moved permanently, But when I use command line, it working and returning html string reuslt.
This is my Code PHP (result not success)
curl_setopt_array($curl, array(
CURLOPT_URL => "https://detail.1688.com/offer/535394058500.html?spm=b26110380.sw1688.mof001.302.6YIDM0&v=1",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_POSTFIELDS => "a=b",
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"content-type: application/x-www-form-urlencoded",
"postman-token: b60107e9-4350-e93f-d6cf-d626505687b8"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response; // return 301 moved permanent
}
And this is in CMD (result success)
curl -X GET 'https://detail.1688.com/offer/535394058500.html?spm=b26110380.sw1688.mof001.302.6YIDM0' -H 'cache-control: no-cache' -H 'content-type: application/x-www-form-urlencoded' -H 'postman-token: 2b11da6f-dcde-d527-289c-bfbf8a85d30c'