永发信息网

帮忙解析一下这段代码,是CURL的间题

答案:1  悬赏:70  手机版
解决时间 2021-04-04 15:14
  • 提问者网友:动次大次蹦擦擦
  • 2021-04-03 21:30
帮忙解析一下这段代码,是CURL的间题
最佳答案
  • 五星知识达人网友:三千妖杀
  • 2021-04-03 21:58
不能用GET, 要用POST, 因为$appid,$secret要放在header里。还有cookie要处理。

public function post($url, $post_data) {
$this->_ch = curl_init();
curl_setopt($this->_ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; rv:22.0) Gecko/20100101 Firefox/22.0');
curl_setopt($this->_ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($this->_ch, CURLOPT_MAXREDIRS, 5);
curl_setopt($this->_ch, CURLOPT_HEADER, 0);
curl_setopt($this->_ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($this->_ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt($this->_ch, CURLOPT_SSL_VERIFYHOST, false );
curl_setopt($this->_ch, CURLOPT_ENCODING, "" );
curl_setopt($this->_ch, CURLOPT_POST, TRUE);
curl_setopt($this->_ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($this->_ch, CURLOPT_COOKIEFILE, getcwd () . '/cookie' );
curl_setopt($this->_ch, CURLOPT_COOKIEJAR, getcwd () . '/cookie' );
curl_setopt($this->_ch, CURLOPT_URL, $url);
$this->_body = curl_exec($this->_ch);
$this->_info = curl_getinfo($this->_ch);
$this->_error = curl_error($this->_ch);
curl_close($this->_ch);
}

Useragent是用户名代理。
可用这个来瞒过网管。

private function _user_agent() {
$version = rand(9, 10);
$major_version = 6;
$minor_version = $version == 8 || $version == 9 ? rand(0, 2) : 2;
$extras = rand(0, 3);
return 'Mozilla/5.0 (compatible; MSIE ' . $version . '.0; Windows NT ' . $major_version . '.' . $minor_version . ($extras == 1 ? '; WOW64' : ($extras == 2 ? '; Win64; IA64' : ($extras == 3 ? '; Win64; x64' : ''))) . ')';
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯