PHP SoapClient无法处理消息,因为内容类型为' text / xml;

时间:2017-07-26 07:48:13

标签: php xml web-services soap soap-client

我无法连接到网络服务并发送/接收数据

错误

  

HTTP,无法处理邮件,因为内容类型为' text / xml;   字符集= 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:不能在堆栈溢出中使用Soap版本1,1和其他解决此错误的示例。

2 个答案:

答案 0 :(得分: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)

接下来检查类型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标准不兼容。

也许您必须使用第三方库或甚至简单的套接字才能使其正常工作。

答案 1 :(得分:0)

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

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