使用 NuSoap 的 HTTP 请求

问题描述 投票:0回答:0

我正在尝试使用 NuSoap 重新创建以下 XML 请求并发送到服务器。服务器需要一个如下所示的请求。

POST /UserRegistratoin/services/Register/ HTTP/1.0
Host: 192.168.0.3:9000
User-Agent: NuSOAP/0.9.5 (1.123)
Content-Type: text/xml; charset=utf-8
SOAPAction: ""
Content-Length: 899

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:v2="http://www.ipma.com.cn/schema/common/v2_1"
xmlns:loc="http://www.csapi.org/schema/parlayx/payment/amount_charging/v2_1/local">
<soapenv:Header>
<v2:RequestSOAPHeader>
        <v2:User>895545</v2:User>
        <v2:Password>098833</v2:Password>
        <v2:timeStamp>20230303060629</v2:timeStamp>
        </v2:RequestSOAPHeader>
</soapenv:Header>
<soapenv:Body>
<chargeAmount>
<endUserIdentifier>737329292929</endUserIdentifier>
<referenceCode>2</referenceCode>
</chargeAmount>
</soapenv:Body>
</soapenv:Envelope>

我已经尝试使用 PHP 和 NuSoap 进行以下操作。

<?php
require 'lib/nusoap.php';

$endpoint = "http://192.168.0.3:9000/UserRegistratoin/services/Register/";

$headers = '
<RequestSOAPHeader>
<User>895545</User>
<Password>098833<Password>
<timeStamp>20230303060629</timeStamp>
</RequestSOAPHeader>';

$client = new nusoap_client($endpoint);

$client->setHeaders($headers);

$client->soap_defencoding = 'UTF-8';
$client->decode_utf8 = false;
$req = "
<chargeAmount>
<endUserIdentifier>737329292929</endUserIdentifier>
<referenceCode>2</referenceCode>
</chargeAmount>
";

$msg = $client->serializeEnvelope($req, '', array(), 'document', 'literal');
$result  = $client->send($msg);
?>

我请求的输出是:

<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body>
<chargeAmount>
<endUserIdentifier>737329292929</endUserIdentifier>
<referenceCode>2</referenceCode>
</chargeAmount>
</SOAP-ENV:Body></SOAP-ENV:Envelope>

如您所见,不包括标头。如何包含标题? 我的代码做错了什么?

更新:

Chris Hass 的输入之后,我注意到 serializeEnvelope 的参数 2 是标题,参数 3 是来自 docs,,

所以现在我的标题看起来像这样。

$headers = '
<v2:RequestSOAPHeader>
<v2:User>**</v2:User>
<v2:Password>**<v2:Password>
<v2:timeStamp>**</v2:timeStamp>
</v2:RequestSOAPHeader>';

此外,参数 3 包含命名空间。所以我建造了

$nsArray = array(
"soapenv" => "http://schemas.xmlsoap.org/soap/envelope/",
"v2" => "http://www.huawei.com.cn/schema/common/v2_1",
"loc" => "http://www.csapi.org/schema/parlayx/payment/amount_charging/v2_1/local"
);
$msg = $client->serializeEnvelope($req, $headers, $nsArray, 'document', 'literal');

请求现在有标头和命名空间,还有其他我不知道的命名空间。

Request
POST /AmountChargingService/services/AmountCharging/ HTTP/1.0
Host: 192.168.0.3:9000
User-Agent: NuSOAP/0.9.5 (1.123)
Content-Type: text/xml; charset=UTF-8
SOAPAction: ""
Content-Length: 1175

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope 

*

> SOAPENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" 
> xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
> xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
> xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"

*


xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:v2="http://www.ipma.com.cn/schema/common/v2_1" 
xmlns:loc="http://www.csapi.org/schema/parlayx/payment/amount_charging/v2_1/local">
<SOAP-ENV:Header>
<v2:RequestSOAPHeader>
<v2:User>**</User>
<v2:Password>**<Password>
<v2:timeStamp>20230303060629</v2:timeStamp>
</v2:RequestSOAPHeader></SOAP-ENV:Header><SOAP-ENV:Body>
<chargeAmount>
<endUserIdentifier>68***7</endUserIdentifier>
<referenceCode>2</referenceCode>
</chargeAmount>
</SOAP-ENV:Body></SOAP-ENV:Envelope>

我收到 HTTP 错误:HTTP 标头后没有数据

php xml soap nusoap
© www.soinside.com 2019 - 2024. All rights reserved.