{"id":425,"title":"php curl\u6293https\u7f51\u5740\u65f6301\u6216302\u6216\u6293\u53d6\u5185\u5bb9\u4e3a\u7a7a\u65f6\u7684\u5904\u7406\u65b9\u6cd5","good":0,"bad":0,"hit":4124,"created_at":"2019-03-22 17:02:33","content":"
\u573a\u666f\uff1a\u68c0\u6d4b\u7f51\u7ad9\u662f\u5426\u5b89\u88c5\u4e86\u67d0\u6bb5\u4ee3\u7801<\/p>
<\/p>
\u7528curl\u6293\u9996\u9875\u4ee3\u7801\u8fdb\u884c\u5206\u6790\uff0c\u4e00\u822chttp\u7f51\u5740\u662f\u6ca1\u95ee\u9898\uff0c\u4f46\u6709\u4e9b\u7f51\u7ad9\u505a\u4e86http\u81ea\u52a8\u8df3\u8f6c\u5230https\u7684\u8bbe\u7f6e\uff0c\u8fd9\u65f6\u53bb\u6293\u5c31\u4f1a\u8fd4\u56de301\u6216302\u4e4b\u7c7b\u7684\u9519\u8bef\uff0c\u5e76\u4e0d\u80fd\u6293\u5230\u9996\u9875\u4ee3\u7801<\/p>
<\/p>
https\u6709\u4e9b\u7f51\u7ad9\u662f\u9700\u8981\u5e26User-Agent\u53cacookie\u624d\u80fd\u6293\u5230\u7684\uff0c\u90a3\u8981\u5982\u4f55\u53bb\u83b7\u5f97cookie\u5462\uff1b\u7ecf\u8fc7\u4e00\u6bb5\u65f6\u95f4\u6298\u817e\uff0c\u6700\u7ec8\u5b9e\u73b0\uff0c\u601d\u8def\uff1a<\/p>
\u5148curl\u8bf7\u6c42\u4e00\u6b21\u53d6\u5f97cookie,\u7136\u540e\u518d\u5c06\u7b2c\u4e00\u6b21\u83b7\u5f97\u7684cookie\u5f04\u51fa\u6765\uff0c\u5c06\u8fd9\u4e2acookie\u653e\u5728header\u4e2d\u518d\u8bf7\u6c42\u4e00\u6b21\u5c31\u53ef\u4ee5\u4e86\uff1b <\/p>
\u7b2c\u4e00\u6b21\u7528\u7684\uff1aget_headers\u53bb\u53d6cookie\u5728windows\u73af\u5883\u4e0b\u53ef\u4ee5\uff0c\u653e\u5230\u7ebf\u4e0a\u4e0d\u884c\uff0c\u540e\u6765\u5c31\u6539\u7528curl\u4e86<\/p>
<\/p>
\/\/\u5934\u5904\u7406<\/p>
$header = [<\/p>
'User-Agent:Mozilla\/5.0 (Windows NT 10.0; WOW64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/70.0.3538.102 Safari\/537.36',<\/p>
'Accept:text\/html,application\/xhtml+xml,application\/xml;q=0.9,image\/webp,image\/apng,*\/*;q=0.8',<\/p>
'Accept-Encoding:gzip, deflate, br',<\/p>
'Accept-Language:zh-CN,zh;q=0.9',<\/p>
];<\/p>
\/\/http<\/p>
$output = $this->_webCurl($domain, $header);<\/p>
if ($output) {<\/p>
if (preg_match_all($str, $output) >= 1) {<\/p>
$result = 1;<\/p>
}<\/p>
}<\/p>
\/\/https<\/p>
if (!$result) {<\/p>
\/\/\u5934\u5904\u7406-linux\u73af\u5883\u5931\u8d25<\/p>
\/\/ $headerArr = get_headers($httpsDomain, 1);<\/p>
\/\/ if (!$headerArr) {<\/p>
\/\/ responseError(600, '\u8bf7\u6c42\u5931\u8d25,\u8bf7\u91cd\u8bd5');<\/p>
\/\/ }<\/p>
\/\/ if ($headerArr && isset($headerArr['Set-Cookie'])) {<\/p>
\/\/ if (is_array($headerArr['Set-Cookie'])) {<\/p>
\/\/ $cookie = $headerArr['Set-Cookie'][0];<\/p>
\/\/ } else {<\/p>
\/\/ $cookie = $headerArr['Set-Cookie'];<\/p>
\/\/ }<\/p>
\/\/ } else {<\/p>
\/\/ $cookie = '';<\/p>
\/\/ }<\/p>
$content = $this->_webCurl($httpsDomain, $header, 1);<\/p>
$pattern = '\/Set-Cookie: .+\/';<\/p>
preg_match($pattern, $content, $matches);<\/p>
if (isset($matches[0])) {<\/p>
$cookie = substr($matches[0], 12);<\/p>
} else {<\/p>
$cookie = '';<\/p>
}<\/p>
array_push($header, "Cookie:$cookie");<\/p>
$output = $this->_webCurl1($httpsDomain, [], '', $cookie);<\/p>
if ($output) {<\/p>
if (preg_match_all($str, $output) >= 1) {<\/p>