2012-08-09 113 views
1

我正在使用GoDaddy的Ultimate Hosting軟件包。該帳戶已安裝了靜態IP和SSL。現在,當我嘗試使用需要靜態IP的API時。但腳本正在發送來自隨機IP的請求。請給我一個方法。來自特定IP的API請求

我的腳本

$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綁定可以幫助我嗎?

+0

這聽起來像一個更適合GoDaddy的技術支持的問題。 – Quentin 2012-08-09 12:20:31

+0

感謝Quentin,反正GoDaddy不會提供完整的固定IP發送請求。但是我聽說可以綁定IP來請求SOAP。可以幫助我嗎? 我發現了一個tuto [here] [1],應該是我的解決方案嗎? [1](http://stackoverflow.com/questions/3444359/is-it-possible-to-specify-the-outgoing-network-interface-to-use-for-a-php-soapcl?rq= 1) – IFightCode 2012-08-09 12:27:05

回答

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

假設你正在使用PHP的捲曲連接到API,你應該每個請求綁定到你的IP:

curl_setopt($ch, CURLOPT_INTERFACE, $myIP); 

要綁定捲曲不同傳出網絡接口或一個不同的IP地址,所有的需要的是執行卷曲請求之前設置CURLOPT_INTERFACE爲適當的值:

+0

感謝阿爾芒,我使用SOAP,我忘了提及。這可以幫助我嗎? http://stackoverflow.com/questions/3444359/is-it-possible-to-specify-the-outgoing-network-interface-to-use-for-a-php-soapcl?rq=1 – IFightCode 2012-08-09 12:37:08

+0

我相信應該是你的解決方案! – 2012-08-09 14:22:09

+0

沒有爲我工作:(我打算離開GoDaddy – IFightCode 2012-08-09 18:18:52

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);