Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.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 SoapClient-操作位置错误_Php_Soap - Fatal编程技术网

PHP SoapClient-操作位置错误

PHP SoapClient-操作位置错误,php,soap,Php,Soap,我使用的是PHPSOAPClient,在获取第三方想要的请求格式时遇到了问题 他们希望这样: POST /service.asmx HTTP/1.1 Host: service.com Content-Type: application/soap+xml; charset=utf-8 Content-Length: length <?xml version="1.0" encoding="utf-8"?> <soap12:Envelope xmlns:xsi="http://

我使用的是PHPSOAPClient,在获取第三方想要的请求格式时遇到了问题

他们希望这样:

POST /service.asmx HTTP/1.1
Host: service.com
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <Order xmlns="http://someservice">
      <json>string</json>
    </Order>
  </soap12:Body>
</soap12:Envelope>
POST /service.asmx HTTP/1.1
Host: service.com
Content-Type: application/soap+xml; charset=utf-8; action="http://someservice"
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Body>
    <Order>
      <json>string</json>
    </Order>
  </soap12:Body>
</soap12:Envelope>

经过几天的努力,我发现了这一点,并最终使被接受的黑客解决方案适合我:


显然,当您使用编写糟糕的Soap API时,您可以做的事情不多。

什么是
$context
?什么是
$request
?这与上面显示的XML有什么关系?我看不到
http://someservice
代码中的任意位置。$上下文与我的一个标题相关,对问题不重要$请求与json相关,只影响json,与XML无关。我所指的url是从他们的WSDL生成的,而不是我的代码。好吧,只是想弄清楚示例代码与示例XML的关系。可能是@miken32 nice的重复,拖拉了一个5个月前的问题,我在回答中引用了这个链接。
$this->client = new SoapClient($this->wsdl, array(
                'soap_version' => SOAP_1_2,
                'encoding' => 'UTF-8',
                'stream_context' => stream_context_create($context),
                'trace' => true,
                'exceptions' => true,
            )
        );
    $json = json_encode($request);

    // Prepare the xml
    $xml = array();
    $xml[] = new SoapVar($json, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema', 'json');

    $this->finalXML = new SoapVar($xml, SOAP_ENC_OBJECT, null, null, 'Order');
    $this->response = $this->client->CreateOrder($this->finalXML);