在肥皂请求中处理回车

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

我正在用PHP编写代码以使用curl发送soap请求。在soap请求中,我必须发送包含许多回车的文本文件的数据。我尝试使用\ n,\ r \ n,\ r \ n,\ n \ n,\ n \ n(13)等发送“回车”但是所有这些都从服务器发出以下错误

发送的数据中的行应仅由单个CR字符分隔。此文件似乎使用LF作为分隔符。

以下是我的Soap请求。我正在开发linux并向Windows服务器发送请求。

<?php
    $submitFileTxt 	  .= "Line1 Text"."\r";
    $submitFileTxt 	  .= "Line2 Text"."\r";
    $submitFIleTxt    .= "Test,Test,Test"."\r";
    $submitFIleTxt    .= "Testtext,Testtext,Testtext"."\r";

    $wsdl 		= "somewsdlurl?wsdl"; 
    $local_cert = "certificate file path";
    $password   = '';
    $xml_post_string = "<s:Envelope xmlns:a='http://www.w3.org/2005/08/addressing' xmlns:s='http://www.w3.org/2003/05/soap-envelope'>
    <s:Header>
    	<a:Action s:mustUnderstand='1'>Data submit method</a:Action>
    </s:Header>
    <s:Body>
    	<Submit>
    	<data xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>
    		<OutputFileBody>{$submitFIleTxt}</OutputFileBody>
    	    <OutputFilename>Some file name</OutputFilename>
    	 </data>
    	</Submit>
     </s:Body>
  </s:Envelope>";	  

   $headers = array(
        "Content-type: application/soap+xml;charset=\"utf-8\"",
        "Accept: text/xml",
        "Cache-Control: no-cache",
        "Pragma: no-cache",
        "Content-length: ".strlen($xml_post_string),
    );  

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,          $wsdl);
    curl_setopt($ch, CURLOPT_SSLCERTTYPE,   "pem");
    curl_setopt($ch, CURLOPT_SSLCERT,      $local_cert);
    curl_setopt($ch, CURLOPT_SSLKEYPASSWD, $password);
    curl_setopt($ch, CURLOPT_SSLKEY,       $local_cert);

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 50);
    curl_setopt($ch, CURLOPT_SSLVERSION, 6);

    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

    $response = curl_exec($ch); 
    $err = curl_error($ch); 
    curl_close($ch);
php web-services curl
1个回答
0
投票

您可以使用&#13;代替\ n \ n和\ &#10;

© www.soinside.com 2019 - 2024. All rights reserved.