当前位置:Gxlcms > PHP教程 > 公司内网环境访问外网需要通过代理,彩信接口在外网环境已经调通,怎么通过curl访问代理服务器访问外网

公司内网环境访问外网需要通过代理,彩信接口在外网环境已经调通,怎么通过curl访问代理服务器访问外网

时间:2021-07-01 10:21:17 帮助过:4人阅读

公司内网环境访问外网需要通过代理,彩信接口在外网环境已经调通,如何通过curl访问代理服务器访问外网
如题,彩信接口在外网状态下已经调通,但公司用的是内网,需要走代理服务器才能访问外网,彩信接口是通过curl post到指定地址的。
$url = 'http://122.200.77.96/sendMMS';
$header[] = "Content-type: text/xml";
$ch = curl_init ($url);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlData);
$response = curl_exec($ch);
if(curl_errno($ch)){
print curl_error($ch);
}
curl_close($ch);
这是post到彩信接口的代码,如何通过curl走代理服务器,再post到指定接口
------解决方案--------------------
curl_setopt($ch, CURLOPT_PROXY, $this->data['proxy']);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
用这两个 但是明明没错 我自己本地 也搞不出来 郁闷
------解决方案--------------------
curl_setopt($ch, CURLOPT_PROXY, "代理服务器地址:端口");
curl_setopt($ch, CURLOPT_PROXYUSERPWD, "用户名:口令"); //没有就不要这句

人气教程排行