首页 > php开发, 技术学习 > PHP调用curl返回Couldn’t resolve host ‘www.xxx.com’

PHP调用curl返回Couldn’t resolve host ‘www.xxx.com’

HP调用curl返回Couldn’t resolve host ‘www.xxx.com’

 

解决方法有2,

1、直接用IP地址

$url = "http://10.133.7.6/cgi-bin/addpost_api“;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);




2、用curl_setopt设置代理

//代理
$port = 8080; 
$list = array('172.23.28.199','172.27.28.234','10.129.128.150','10.133.0.241');
$ipIndex = rand(0, count($list) - 1);
$ip = $list[$ipIndex];

$cgiUrl = 'http://chong.qq.com/tws/spapi/GetChargeFile?';

$ch = curl_init();
curl_setopt ($ch, CURLOPT_PROXY, 'http://' . $ip . ':' . $port);
curl_setopt($ch, CURLOPT_URL, $cgiUrl);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);

 

附:

可设置的CURLOPT_XXX选项:http://www.php.net/manual/zh/function.curl-setopt.php

PHP HTTP操作基于curl封装的更好用的库:http://docs.guzzlephp.org/en/latest/

HP调用curl返回Couldn’t resolve host ‘www.xxx.co […]

  1. 还没有评论
评论提交中, 请稍候...

留言

(Spamcheck Enabled)

Trackbacks & Pingbacks ( 0 )
  1. 还没有 trackbacks