2015-01-05 49 views
0

我希望有人能幫助解決這個問題。我正嘗試通過UKMail提供的肥皂服務登錄。我的代碼看起來像這樣至今:使用PHP Curl發佈到Soap服務導致對象未設置錯誤

<?php 
$data = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:ser="http://www.UKMail.com/Services/Contracts/ServiceContracts" 
xmlns:dat="http://www.UKMail.com/Services/Contracts/DataContracts"> 
<soapenv:Header/>  
<soapenv:Body>  
<ser:Login>   
<ser:LoginWebRequest>   
<dat:Username>xxx</dat:Username>    
<dat:Password>xxx</dat:Password>  
</ser:LoginWebRequest>  
</ser:Login>  
</soapenv:Body> 
</soapenv:Envelope>'; 

$curl = new cURL(); 

$page = $curl->soap_post('https://api.ukmail.com/Services/UKMAuthenticationServices/UKMAuthenticationService.svc?wsdl',$data); 

echo $page; 



class cURL { 
var $headers; 
var $user_agent; 
var $compression; 
var $cookie_file; 
var $cookies; 
var $proxy; 

function cURL($cookies=TRUE, $cookie_file='cookies.txt', $compression='gzip,deflate', $proxy='') { 
    $this->headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'; 
    $this->headers[] = 'Connection: Keep-Alive'; 
    $this->headers[] = 'Content-type: application/x-www-form-urlencoded;charset=windows-1251'; 
    $this->user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7 (.NET CLR 3.5.30729)'; 
    $this->compression=$compression; 
    $this->proxy=$proxy; 
    $this->cookies=$cookies; 
    $this->cookie_file=$cookie_file; 
} 



function soap_post($url,$data){ 

$headers = array( 
    'Content-type: text/xml; charset=utf-8', 
    'Content-Length: '.strlen($data), 
    'Accept: text/xml', 
    'Cache-Control: no-cache', 
    'Pragma: no-cache', 
    'SOAPAction: "http://www.UKMail.com/Services/IUKMAuthenticationService/Login"', 
    'Expect: ' 
); 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_TIMEOUT, 60); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
curl_setopt($ch, CURLOPT_USERAGENT, $this->user_agent); 
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 

$out = curl_exec($ch); 
return $out; 
} 

} 

?> 

運行上面的代碼給了我不設置到對象錯誤的實例對象,我不能爲我的生命弄清楚我要去哪裏錯了。我曾嘗試使用PHP的SoapClient,但它在我的客戶端生產服務器上效果不佳,因此我正在使用curl。

我忘了提及您在代碼中看到的xml實際上是由UKMail自己提供的,如果這樣做有任何區別的話。

的錯誤:不設置爲一個對象

回答

0

的實例 對象引用只是插入URL中的WSDL文件到的soapUI其中創建的XML請求。所以我應對了它創建的xml,並在腳本中使用它,它工作正常!據我所知,我寫的內容和soapUI生成的用戶名和密碼字段之間唯一的區別在於順序錯誤。

0

我有改變的,你一點點的代碼,使之爲我工作,給這一個嘗試

<?php 
    $data = "<?xml version='1.0' encoding='UTF-8'?> 
    <soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' 
xmlns:ser='http://www.UKMail.com/Services/Contracts/ServiceContracts' 
xmlns:dat='http://www.UKMail.com/Services/Contracts/DataContracts'> 
<soapenv:Header/> 
<soapenv:Body> 
<ser:Login> 
<ser:loginWebRequest> 
<dat:Password>xxxxxxxxxxx</dat:Password> 
<dat:Username>xxxxxxxxxxx</dat:Username> 
</ser:loginWebRequest> 
</ser:Login> 
</soapenv:Body> 
</soapenv:Envelope>"; 

    $curl = new cURL(); 

    echo $page = $curl->soap_post('https://api.ukmail.com/Services/UKMAuthenticationServices/UKMAuthenticationService.svc?wsdl',$data); 





    class cURL { 


    function soap_post($url,$data){ 

    $headers = array( 
     'Content-type: text/xml; charset=utf-8', 
     'Content-Length: '.strlen($data), 
     'Accept: text/xml', 
     'Cache-Control: no-cache', 
     'Pragma: no-cache', 
     'SOAPAction: "http://www.UKMail.com/Services/IUKMAuthenticationService/Login"', 
    ); 

    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 60); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
    curl_setopt($ch, CURLOPT_POST, true); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 

    $out = curl_exec($ch); 
    return $out; 
    } 

    } 

    ?> 
相關問題