2017-05-16 2 views
1

Code:Warum wird meine cURL in PHP 403 verboten, während cURL in der Shell 200 bekommt?

$ch = curl_init(); 
curl_setopt ($ch, CURLOPT_URL, "https://detail.1688.com/offer/543783250479.html?sk=consign"); 
curl_setopt($ch, CURLOPT_HEADER, true); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
$a = curl_exec($ch); 
$data = curl_exec($ch); 
curl_close($ch); 
var_dump($data); 

Ergebnis:

string(339) "HTTP/1.1 403 Forbidden 
Server: nginx/1.11.1 
Date: Tue, 16 May 2017 03:46:32 GMT 
Content-Type: text/html; charset=utf-8 
Content-Length: 169 
Connection: keep-alive 

<html> 
<head><title>403 Forbidden</title></head> 
<body bgcolor="white"> 
<center><h1>403 Forbidden</h1></center> 
<hr><center>nginx/1.11.1</center> 
</body> 
</html> 
" 

Während ich curl -I https://detail.1688.com/offer/543783250479.html?sk=consign in meiner Shell ausführen, gibt es 200:

HTTP/1.1 200 OK 
Date: Tue, 16 May 2017 03:46:51 GMT 
Content-Type: text/html;charset=GBK 
Connection: keep-alive 
Vary: Accept-Encoding 
Expires: Thu, 01-Jan-1970 00:00:00 GMT 
Cache-Control: max-age=0,s-maxage=0 
b2c_auction: 543783250479 
atp_isdpp: 99vb2b-2295161471 
page_cache_info: {"is_new":true,"create_time":"2017-05-16T11:46:51","expire_time":3600000} 
X-Cache: MISS TCP_REFRESH_MISS dirn:-2:-2 
Via: aserver010103196008.et2[69,200-0,M] 
url-hash: id=543783250479&detail.1688.com 
Server: Tengine/Aserver 
Strict-Transport-Security: max-age=31536000 
Timing-Allow-Origin: * 
EagleEye-TraceId: 0b83e0c214949064118297808e926 

Könnte jemand bitte geben Sie mir einige Hinweise darüber, warum ich 403 von cURL in PHP?

Umwelt:

Copyright (c) 1997-2016 The PHP Group 
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies 
    with Zend OPcache v7.0.8-2+deb.sury.org~xenial+1, Copyright (c) 1999-2016, by Zend Technologies 
    with blackfire v1.10.6, https://blackfire.io, by Blackfireio Inc. 
+1

Ich habe Ihren Code und es versucht, funktioniert normal, versuche es mit einer anderen IP-Adresse, du wurdest möglicherweise gesperrt. –

Antwort

1

Die Rückkehr Header ohne mit einem useragent:

HTTP/1.1 302 Moved Temporarily 
Date: Tue, 16 May 2017 04:15:46 GMT 
Content-Type: text/html 
Content-Length: 266 
Connection: keep-alive 
Location: http://127.0.0.1/?sk=consign 
X-Cache: MISS TCP_MISS dirn:-2:-2 
Via: aserver010103196008.et2[0,302-0,M] 
url-hash: id=543783250479&detail.1688.com 
Server: Tengine/Aserver 
Strict-Transport-Security: max-age=31536000 
Timing-Allow-Origin: * 
EagleEye-TraceId: 0b83dc9c14949081466171756eb58d 

Der wichtigste Teil ist:

Location: http://127.0.0.1/?sk=consign 

wenn ich ein useragent verwenden, erhalte ich:

HTTP/1.1 200 OK 
Date: Tue, 16 May 2017 04:17:30 GMT 
Content-Type: text/html;charset=GBK 
Transfer-Encoding: chunked 
Connection: keep-alive 
Vary: Accept-Encoding 
Expires: Thu, 01-Jan-1970 00:00:00 GMT 
Cache-Control: max-age=0,s-maxage=0 
b2c_auction: 543783250479 
atp_isdpp: 99vb2b-2295161471 
page_cache_info: {"is_new":true,"create_time":"2017-05-16T12:17:30","expire_time":3600000} 
X-Cache: MISS TCP_MISS dirn:-2:-2 
Via: aserver011128044194.eu13[106,200-0,M] 
url-hash: id=543783250479&detail.1688.com 
Server: Tengine/Aserver 
Strict-Transport-Security: max-age=31536000 
Timing-Allow-Origin: * 
EagleEye-TraceId: 0b802cd414949082503341644e23a0 

Was ist richtig und es gibt den gewünschten html


-Code verwendet:

$url = "http://detail.1688.com/offer/543783250479.html?sk=consign"; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:53.0) Gecko/20100101 Firefox/53.0"); 
$html = curl_exec($ch); 
curl_close($ch); 
print $html; 
0

In curl -I für Kopf Anfrage steht. Versuchen Sie, den Kopf Anfrage in Ihrer PHP als Einstellung:

curl_setopt($ch, CURLOPT_NOBODY, true); 

Und versuchen Sie es mal