来自特定IP的API请求

时间:2012-08-09 12:18:10

标签: php api ip

我正在使用GoDaddy的Ultimate Hosting包。该帐户安装了静态IP和SSL。现在,当我尝试使用需要静态IP的API时。但是脚本正在从随机IP发送请求。请建议我一个方法。

我的剧本

$soap_exception_occured = false;

$wsdl_path = 'http://vrapi.sslwireless.com/?wsdl';

$response = '';

ini_set('soap.wsdl_cache_enabled', '0'); // disabling WSDL cache

try {
    $client = new SoapClient($wsdl_path);
    }

catch(SoapFault $exception) {
    $soap_exception_occured = true;
    $response .= '\nError occoured when connecting to the SMS SOAP Server!';
    $response .= '\nSoap Exception: '.$exception;
    } 

我正在使用SOAP。 IP绑定可以帮助我吗?先谢谢。

3 个答案:

答案 0 :(得分:2)

假设您使用php的curl连接到该API,您应该将每个请求绑定到您的IP:

curl_setopt($ch, CURLOPT_INTERFACE, $myIP);

要将CURL绑定到不同的传出网络接口或不同的IP地址,所需的只是在执行CURL请求之前将CURLOPT_INTERFACE设置为适当的值:

答案 1 :(得分:1)

试试这个,让我知道发生了什么

$soap_exception_occured = false;
$ipandport = array(
    'socket' => array(
        'bindto' => 'xx.xx.xx.xx:port',
     ),
);
$setip  = stream_context_create(ipandport);

$wsdl_path = 'http://vrapi.sslwireless.com/?wsdl';

$response = '';

ini_set('soap.wsdl_cache_enabled', '0'); // disabling WSDL cache

try {
    $client = new SoapClient($wsdl_path, array('stream_context' => $setip));
    }

catch(SoapFault $exception) {
    $soap_exception_occured = true;
    $response .= '\nError occoured when connecting to the SMS SOAP Server!';
    $response .= '\nSoap Exception: '.$exception;
    }

答案 2 :(得分:0)

如果没有file_get_contents:

,这个帖子就不完整了
$opts = array(
    'socket' => array(
        'bindto' => 'xx.xx.xx.xx:0',
    )
);

$context = stream_context_create($opts);

echo file_get_contents('http://www.example.com', false, $context);