Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP NuSoap中的XML请求-“;HTTP/1.1 400错误请求“;_Php_Xml_Soap_Nusoap - Fatal编程技术网

PHP NuSoap中的XML请求-“;HTTP/1.1 400错误请求“;

PHP NuSoap中的XML请求-“;HTTP/1.1 400错误请求“;,php,xml,soap,nusoap,Php,Xml,Soap,Nusoap,我在PHP中使用NuSoap连接到API 目前,我只是简单地尝试发送一个由提供API的公司提供的示例XML字符串,但是我收到一个HTTP/1.1400错误请求 我直接向该公司提出了这个问题,但他们说,当他们使用他们提供的XML以及其他客户时,他们没有任何问题 我尝试发送的XML是: ![CDATA[<?xml version="1.0" encoding="utf-8" ?> <Service> <Name><![CDATA[Demo]]>&l

我在PHP中使用NuSoap连接到API

目前,我只是简单地尝试发送一个由提供API的公司提供的示例XML字符串,但是我收到一个
HTTP/1.1400错误请求

我直接向该公司提出了这个问题,但他们说,当他们使用他们提供的XML以及其他客户时,他们没有任何问题

我尝试发送的XML是:

![CDATA[<?xml version="1.0" encoding="utf-8" ?>
<Service>
  <Name><![CDATA[Demo]]></Name>
  <Description><![CDATA[Demo Service]]></Description>
  <Version>1.0</Version>
  <Nodes>
    <Node NodeType="Start" NodeID="5" Description="">
      <!-- Comments can be included -->
      <MandatoryProperties>
        <Property Name="MaxLength" Value="0"/>
        <Property Name="EnableSpeedDial" Value="False"/>
      </MandatoryProperties>
     <OptionalSettings/>
      <Branches>
        <Branch Name="Continue" NodeID="20" Description=""/>
      </Branches>
      <DynamicBranches/>
      <DynamicProperties/>
    </Node>
    <Node NodeType="DeliverCall" NodeID="20" Description="Home Phone">
      <MandatoryProperties>
        <Property Name="DestinationNumber" Value="01132211444"/>
        <Property Name="RingDuration" Value="60"/>
      </MandatoryProperties>
      <OptionalSettings/>
      <Branches>
      </Branches>
      <DynamicBranches/>
      <DynamicProperties/>
    </Node>
  </Nodes>
</Service>]]
我曾经验证过XML,因为我没有XML方面的经验,这是我不得不使用它的少数几次之一,因此我不想在发现任何语法错误时大惊小怪,但验证工具提供的错误是:

我已经检查过XML上是否没有前导或尾随空格

我注意到,在XML中,它将编码设置为
utf-8
。然而,我的请求中的编码似乎是
ISO
——尽管看起来XML字符串中没有任何特殊字符或任何内容

请求数据:

POST /dev/aspapi/api.asmx HTTP/1.0
Host: www.xxxxx.com
User-Agent: NuSOAP/0.9.5 (1.123)
Content-Type: text/xml; charset=ISO-8859-1
SOAPAction: "https://www.xxxxx.com/ASPAPI/ValidateService"
Authorization: Basic bWVkaWFoYXdrOm1lZGlhaGF3aw==
Content-Length: 2127
如果有人能发现这有什么问题,我将不胜感激

完整连接脚本:

<?php

require_once('./nusoap.php');

error_reporting(E_ALL);
ini_set("display_errors", true);

$client = new nusoap_client('http://xxx.xxx/api.asmx', 'wsdl');

$client->setCredentials('xxxxx', 'xxxxx'); 
$client->response_timeout = 120;

$err = $client->getError();

if($err) {
    echo 'ERROR<br /><pre>' . $err . '</pre><br />';
    exit;
} else {
    echo "<strong><em>Sucessfull connection</em></strong><br /><br />";
}

$proxy = $client->getProxy();

$proxy->setHeaders('<soap:Header><AuthenticationSoapHeader xmlns="https://www.xxxxx.com/aspapi"><Token>xxxxx</Token></AuthenticationSoapHeader></soap:Header>');

$xml = '
![CDATA[<?xml version="1.0" encoding="utf-8" ?>
<Service>
  <Name><![CDATA[Demo]]></Name>
  <Description><![CDATA[Demo Service]]></Description>
  <Version>1.0</Version>
  <Nodes>
    <Node NodeType="Start" NodeID="5" Description="">
      <!-- Comments can be included -->
      <MandatoryProperties>
        <Property Name="MaxLength" Value="0"/>
        <Property Name="EnableSpeedDial" Value="False"/>
      </MandatoryProperties>
     <OptionalSettings/>
      <Branches>
        <Branch Name="Continue" NodeID="20" Description=""/>
      </Branches>
      <DynamicBranches/>
      <DynamicProperties/>
    </Node>
    <Node NodeType="DeliverCall" NodeID="20" Description="Home Phone">
      <MandatoryProperties>
        <Property Name="DestinationNumber" Value="01132211444"/>
        <Property Name="RingDuration" Value="60"/>
      </MandatoryProperties>
      <OptionalSettings/>
      <Branches>
      </Branches>
      <DynamicBranches/>
      <DynamicProperties/>
    </Node>
  </Nodes>
</Service>]]';

$result = $proxy->call('ValidateService', array('serviceXML' => $xml));

$err = $proxy->getError();
if($err) {
    echo 'ERROR<br /><pre>' . $err . '</pre><br />';
    echo '<strong>Request:</strong>';
    echo '<pre>'; print_r($proxy->request); echo '</pre>';
    echo '<strong>Response:</strong>';
    echo '<pre>'; print_r($proxy->response); echo '</pre>';
    exit;
} else {
    echo "<strong><em>Sucessfull connection</em></strong><br /><br />";
}
?>

问题在于标题

打开和关闭标记导致HTTP错误400“错误请求”

$proxy->setHeaders('xxxxx');
应该是

$proxy->setHeaders('xxxxx');

尝试更改此
![CDATA[
到此
并从xml末尾删除
]
,因为使用
![CDATA[
开头和
]
结尾xml不太好-formed@elitechief21XML必须用
CDATA
包装(根据提供API的公司)API的创建者有一个测试门户,允许您验证XML字符串——当我将XML字符串放入他们门户中的验证工具时,它返回一个成功。因此,这肯定与我如何发送它有关。这听起来不太正确……您使用它来指定不应由xml解析器解析的文本数据。将
放在xml的根元素之外是格式不好的,也没有任何意义,因为你基本上是告诉解析器不要解析任何xml,不管xml的格式如何,你能发布你正在上传的代码吗?我在使用基于https的c#webservice时遇到了类似的问题。我收到HTTP错误:不支持的HTTP响应状态400错误请求。我想我也有头球问题,但根据你的解决方案,我没有代币。
<?php

require_once('./nusoap.php');

error_reporting(E_ALL);
ini_set("display_errors", true);

$client = new nusoap_client('http://xxx.xxx/api.asmx', 'wsdl');

$client->setCredentials('xxxxx', 'xxxxx'); 
$client->response_timeout = 120;

$err = $client->getError();

if($err) {
    echo 'ERROR<br /><pre>' . $err . '</pre><br />';
    exit;
} else {
    echo "<strong><em>Sucessfull connection</em></strong><br /><br />";
}

$proxy = $client->getProxy();

$proxy->setHeaders('<soap:Header><AuthenticationSoapHeader xmlns="https://www.xxxxx.com/aspapi"><Token>xxxxx</Token></AuthenticationSoapHeader></soap:Header>');

$xml = '
![CDATA[<?xml version="1.0" encoding="utf-8" ?>
<Service>
  <Name><![CDATA[Demo]]></Name>
  <Description><![CDATA[Demo Service]]></Description>
  <Version>1.0</Version>
  <Nodes>
    <Node NodeType="Start" NodeID="5" Description="">
      <!-- Comments can be included -->
      <MandatoryProperties>
        <Property Name="MaxLength" Value="0"/>
        <Property Name="EnableSpeedDial" Value="False"/>
      </MandatoryProperties>
     <OptionalSettings/>
      <Branches>
        <Branch Name="Continue" NodeID="20" Description=""/>
      </Branches>
      <DynamicBranches/>
      <DynamicProperties/>
    </Node>
    <Node NodeType="DeliverCall" NodeID="20" Description="Home Phone">
      <MandatoryProperties>
        <Property Name="DestinationNumber" Value="01132211444"/>
        <Property Name="RingDuration" Value="60"/>
      </MandatoryProperties>
      <OptionalSettings/>
      <Branches>
      </Branches>
      <DynamicBranches/>
      <DynamicProperties/>
    </Node>
  </Nodes>
</Service>]]';

$result = $proxy->call('ValidateService', array('serviceXML' => $xml));

$err = $proxy->getError();
if($err) {
    echo 'ERROR<br /><pre>' . $err . '</pre><br />';
    echo '<strong>Request:</strong>';
    echo '<pre>'; print_r($proxy->request); echo '</pre>';
    echo '<strong>Response:</strong>';
    echo '<pre>'; print_r($proxy->response); echo '</pre>';
    exit;
} else {
    echo "<strong><em>Sucessfull connection</em></strong><br /><br />";
}
?>
Sucessfull connection

ERROR
HTTP Error: Unsupported HTTP response status 400 Bad Request (soapclient->response has contents of the response)

Request:
POST /dev/aspapi/api.asmx HTTP/1.0
Host: www.xxxxx.com
User-Agent: NuSOAP/0.9.5 (1.123)
Content-Type: text/xml; charset=ISO-8859-1
SOAPAction: "https://www.xxxxx.com/ASPAPI/ValidateService"
Authorization: Basic bWVkaWFoYXdrOm1lZGlhaGF3aw==
Content-Length: 2127

<TOKEN IS HERE IN OUTPUT>
![CDATA[<?xml version="1.0" encoding="utf-8" ?>
<Service>
  <Name><![CDATA[Demo]]></Name>
  <Description><![CDATA[Demo Service]]></Description>
  <Version>1.0</Version>
  <Nodes>
    <Node NodeType="Start" NodeID="5" Description="">
      <!-- Comments can be included -->
      <MandatoryProperties>
        <Property Name="MaxLength" Value="0"/>
        <Property Name="EnableSpeedDial" Value="False"/>
      </MandatoryProperties>
     <OptionalSettings/>
      <Branches>
        <Branch Name="Continue" NodeID="20" Description=""/>
      </Branches>
      <DynamicBranches/>
      <DynamicProperties/>
    </Node>
    <Node NodeType="DeliverCall" NodeID="20" Description="Home Phone">
      <MandatoryProperties>
        <Property Name="DestinationNumber" Value="01132211444"/>
        <Property Name="RingDuration" Value="60"/>
      </MandatoryProperties>
      <OptionalSettings/>
      <Branches>
      </Branches>
      <DynamicBranches/>
      <DynamicProperties/>
    </Node>
  </Nodes>
</Service>]]

Response:

HTTP/1.1 100 Continue

HTTP/1.1 400 Bad Request
Date: Fri, 24 Jan 2014 16:28:39 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET 2.0
MicrosoftOfficeWebServer: 5.0_Pub
X-Powered-By: ASP.NET
X-AspNet-Version: 4.0.30319
Cache-Control: private
Content-Type: text/xml; charset=utf-8
Content-Length: 2
Connection: close
$proxy->setHeaders('<soap:Header><AuthenticationSoapHeader xmlns="https://www.xxxxx.com/aspapi"><Token>xxxxx</Token></AuthenticationSoapHeader></soap:Header>');
$proxy->setHeaders('<AuthenticationSoapHeader xmlns="https://www.xxxxx.com/aspapi"><Token>xxxxx</Token></AuthenticationSoapHeader>');