簡體   English   中英

PHP SoapClient 無法處理消息,因為內容類型為 'text/xml;

[英]PHP SoapClient Cannot process the message because the content type 'text/xml;

我無法連接到網絡服務並發送/接收數據

錯誤

HTTP, 無法處理消息,因為內容類型為 'text/xml; charset=utf-8' 不是預期的類型 'application/soap+xml; 字符集=utf-8'。

代碼

$parameters = [
        'UserName' => 12324,
        'Password' => 432123,
        'Bill_Id' => 153585611140,
        'Payment_Id' => 8560103,
    ];

    $url="https://bill.samanepay.com/CheckBill/BillStateService.svc?wsdl";
    $method = "VerifyBillPaymentWithAddData";

    $client = new SoapClient($url);

    try{

        $info = $client->__call($method, array($parameters));

    }catch (SoapFault $fault){  

        die($fault->faultcode.','.$fault->faultstring);

    }

Notice :在 stackoverflow 中,此錯誤的 Soap 版本 1,1 和其他解決示例不起作用。

你可以試試

$url = "https://bill.samanepay.com/CheckBill/BillStateService.svc?wsdl";

try {
    $client = new SoapClient($url, [
        "soap_version" => SOAP_1_2, // SOAP_1_1
        'cache_wsdl' => WSDL_CACHE_NONE, // WSDL_CACHE_MEMORY
        'trace' => 1,
        'exception' => 1,
        'keep_alive' => false,
        'connection_timeout' => 500000
    ]);
    print_r($client->__getFunctions());
} catch (SOAPFault $f) {
    error_log('ERROR => '.$f);
}

驗證您的方法名稱是否正確。

在那里你可以看到方法

VerifyBillPaymentWithAddDataResponse VerifyBillPaymentWithAddData(VerifyBillPaymentWithAddData $parameters)

接下來是檢查 Type VerifyBillPaymentWithAddData以及參數是否可以是數組。 您也可以測試通過調用該方法

$client->VerifyBillPaymentWithAddData([
    'UserName' => 12324,
    'Password' => 432123,
    'Bill_Id' => 153585611140,
    'Payment_Id' => 8560103,
]);

或者你的,除了額外的數組

$info = $client->__call($method, $parameters);

編輯:假設到https://stackoverflow.com/a/5409465/1152471 ,錯誤可能在服務器端,因為服務器發送回與 SOAP 1.2 標准不兼容的標頭。

也許您必須使用第三方庫甚至是簡單的套接字才能使其正常工作。

只需使用以下功能。 玩得開心!

function WebServices($function, $parameters){
        
    $username = '***';
    $password = '***';

    $url = "http://*.*.*.*/*/*/*WebService.svc?wsdl";
    $service_url = 'http://*.*.*.*/*/*/*WebService.svc';
    

    
    $client = new SoapClient($url, [
        "soap_version" => SOAP_1_2,
        "UserName"=>$username, 
        "Password"=>$password,
        "SOAPAction"=>"http://tempuri.org/I*WebService/$function",
        'cache_wsdl' => WSDL_CACHE_NONE, // WSDL_CACHE_MEMORY
        'trace' => 1,
        'exception' => 1,
        'keep_alive' => false,
        'connection_timeout' => 500000
    ]);
    $action = new \SoapHeader('http://www.w3.org/2005/08/addressing', 'Action', "http://tempuri.org/I*WebService/$function");
    $to = new \SoapHeader('http://www.w3.org/2005/08/addressing', 'To', $service_url);
    $client->__setSoapHeaders([$action, $to]);
    try{
        return $client->__call($function, $parameters);  
    } catch(SoapFault $e){
        return $e->getMessage();
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM