php - SOAP:HTTP 错误请求

标签 php web-services .htaccess http soap

请求 SOAP 调用后出现以下错误。

fault code: HTTP, fault string: Bad Request

这是一条格式错误的消息吗?

try{
    $client = new SoapClient("http://ip_add/something.asmx?WSDL", array("trace" => true, 'exceptions' => 1));

    $params = new \SoapVar('<?xml version="1.0" encoding="utf-8"?>
                <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                <soap:Body>
                    <RemittanceService xmlns="http://tempuri.org/">
                    <CreditTxnMessage xmlns="http://my_url">
                    <Corporate_UID xmlns="">66666</Corporate_UID>
                    <Mandate_Type xmlns="">P</Mandate_Type>
                    <MICR_No xsi:nil="true" xmlns="" />
                    <Instrument_No xsi:nil="true" xmlns="" />
                    <Remitter_Address1 xmlns="">285 enfiled pl</Remitter_Address1>
                    <Remitter_Address2 xmlns="">mississauga</Remitter_Address2>
                    <Remitter_Address3 xmlns="">16y2n4</Remitter_Address3>
                    <Remitter_Country xmlns="">Canada</Remitter_Country>
                    <Remitter_ZIP_Code xsi:nil="true" xmlns="" />
                    <Remitter_EmailID xsi:nil="true" xmlns="" />
                    <Remitter_Contact_No xmlns="" />
                    <Beneficiary_ZIP_Code xsi:nil="true" xmlns="" />
                    <Beneficiary_EmailID xsi:nil="true" xmlns="" />
                    <Beneficiary_Contact_No xmlns="" />
                    <Beneficiary_Bank_Name xmlns="">PNB</Beneficiary_Bank_Name>
                    </CreditTxnMessage>
                    </RemittanceService>
                </soap:Body>
                </soap:Envelope>', XSD_ANYXML);

    $result = $client->__soapCall('RemittanceService', array($params));
    highlight_string($client->__getLastRequest());
}
catch(SoapFault $fault){
    die("SOAP Fault:<br />fault code: {$fault->faultcode}, fault string: {$fault->faultstring}");
}

我不知道这里出了什么问题。

堆栈跟踪

SoapFault exception: [HTTP] Bad Request in /var/www/mtes/public_html/application/controllers/bank_api_pnb.php:146
Stack trace:
#0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'http://124.124....', 'http://tempuri....', 1, 0)
#1 /var/www/mtes/public_html/application/controllers/bank_api_pnb.php(146): SoapClient->__soapCall('RemittanceServi...', Array)
#2 [internal function]: Bank_api_pnb->test()
#3 /var/www/mtes/public_html/system/core/CodeIgniter.php(359): call_user_func_array(Array, Array)
#4 /var/www/mtes/public_html/index.php(220): require_once('/var/www/mtes/p...')
#5 {main}

最佳答案

SoapClient 的重点是将调用转换为 xml;所以你不应该手动执行此操作。试试这个:

try {
    $client = new SoapClient("http://ip_add/something.asmx?WSDL", array("trace" => true, 'exceptions' => 1));

    $result = $client->RemittanceService(array(
            'CreditTxnMessage' => array(
                    'Corporate_UID' => 66666,
                    'Mandate_Type' => 'P',
                    'MICR_No' => null,
                     /* you get the idea */
                    'Beneficiary_Contact_No' => '',
                    'Beneficiary_Bank_Name' => 'PNB'
            )
    ));

    highlight_string($client->__getLastRequest());
}
catch(SoapFault $fault){
    die("SOAP Fault:<br />fault code: {$fault->faultcode}, fault string: {$fault->faultstring}");
}

参数的确切格式及其名称将在 WSDL 中指定。

关于php - SOAP:HTTP 错误请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31076728/

相关文章:

php - 具有连接的 Doctrine 查询构建器返回实体数组而不是分组结果

c# - 是否可以将数据从 AngularJS 传递到 Web 服务中带有模型参数的函数?

apache - 本地站点重定向到实时站点

php - 用于上传个人资料图片的 SWITCH 语句

php - Slim Basic Auth 的身份验证失败

javascript - 如何在提交表单后显示下拉菜单过滤器选定的值?

javascript - Node.js 作为 JSON 转发器

.net - 我可以在桌面窗口上使用 DPWS 吗?

apache - .htaccess 在文件不存在时重定向

php - 实时主机上的 codeigniter 内部服务器错误