尝试通过cURL将XML文件发送到Web服务时Soapenv错误

时间:2017-04-20 15:20:53

标签: php web-services curl soap

我在使用soapenv,webservice和webdav时遇到了问题。

我发送pdf文件&一个xml文件,列出了enveloppe的所有pdf文件。 然后我调用web服务,通​​过发送带有cURL的技术xml来“启动”xml中列出的pdf文件(在webdav中)。

这里是webdav中的XML示例:

<?xml version='1.0' encoding='ISO-8859-1' ?>
<actes:Acte xmlns:actes='http://' xmlns:insee='http://' xmlns:xsi='http://' xsi:schemaLocation='http://' actes:Date='2017-04-20' actes:NumeroInterne='lmc117M235' actes:CodeNatureActe='4'>
<actes:CodeMatiere1 actes:CodeMatiere="1"/>
<actes:CodeMatiere2 actes:CodeMatiere="4"/>
<actes:Objet>TRAVAUX DE REMPLACEMENT DES RESEAUX EAUX PLUVIALES ET RESEAUX EAUX USEES - RUE ALBERT CAMUS, RUE ANDRE MALRAUX ET CHEMIN BARRIEU - COMMUNE DE BLAGNAC - 17M024PA</actes:Objet>
<actes:ClassificationDateVersion>2003-06-25</actes:ClassificationDateVersion><actes:Document><actes:NomFichier>031-999100046-20170420-lmc117M235-CC-1-1_1.pdf</actes:NomFichier></actes:Document>
<actes:Annexes actes:Nombre="22">
<actes:Annexe><actes:NomFichier>031-999100046-20170420-lmc117M235-CC-1-1_02.pdf</actes:NomFichier></actes:Annexe>
<actes:Annexe><actes:NomFichier>031-999100046-20170420-lmc117M235-CC-1-1_03.pdf</actes:NomFichier></actes:Annexe>
<actes:Annexe><actes:NomFichier>031-999100046-20170420-lmc117M235-CC-1-1_04.pdf</actes:NomFichier></actes:Annexe>
<actes:Annexe><actes:NomFichier>031-999100046-20170420-lmc117M235-CC-1-1_05.pdf</actes:NomFichier></actes:Annexe>
<actes:Annexe><actes:NomFichier>031-999100046-20170420-lmc117M235-CC-1-1_06.pdf</actes:NomFichier></actes:Annexe>
<actes:Annexe><actes:NomFichier>031-999100046-20170420-lmc117M235-CC-1-1_07.pdf</actes:NomFichier></actes:Annexe>
<actes:Annexe><actes:NomFichier>031-999100046-20170420-lmc117M235-CC-1-1_08.pdf</actes:NomFichier></actes:Annexe>
<actes:Annexe><actes:NomFichier>031-999100046-20170420-lmc117M235-CC-1-1_09.pdf</actes:NomFichier></actes:Annexe>
<actes:Annexe><actes:NomFichier>031-999100046-20170420-lmc117M235-CC-1-1_10.pdf</actes:NomFichier></actes:Annexe>
<actes:Annexe><actes:NomFichier>031-999100046-20170420-lmc117M235-CC-1-1_11.pdf</actes:NomFichier></actes:Annexe>
<actes:Annexe><actes:NomFichier>031-999100046-20170420-lmc117M235-CC-1-1_12.pdf</actes:NomFichier></actes:Annexe>
<actes:Annexe><actes:NomFichier>031-999100046-20170420-lmc117M235-CC-1-1_13.pdf</actes:NomFichier></actes:Annexe>
<actes:Annexe><actes:NomFichier>031-999100046-20170420-lmc117M235-CC-1-1_14.pdf</actes:NomFichier></actes:Annexe>
<actes:Annexe><actes:NomFichier>031-999100046-20170420-lmc117M235-CC-1-1_15.pdf</actes:NomFichier></actes:Annexe>
<actes:Annexe><actes:NomFichier>031-999100046-20170420-lmc117M235-CC-1-1_16.pdf</actes:NomFichier></actes:Annexe>
<actes:Annexe><actes:NomFichier>031-999100046-20170420-lmc117M235-CC-1-1_17.pdf</actes:NomFichier></actes:Annexe>
<actes:Annexe><actes:NomFichier>031-999100046-20170420-lmc117M235-CC-1-1_18.pdf</actes:NomFichier></actes:Annexe>
<actes:Annexe><actes:NomFichier>031-999100046-20170420-lmc117M235-CC-1-1_19.pdf</actes:NomFichier></actes:Annexe>
<actes:Annexe><actes:NomFichier>031-999100046-20170420-lmc117M235-CC-1-1_20.pdf</actes:NomFichier></actes:Annexe>
<actes:Annexe><actes:NomFichier>031-999100046-20170420-lmc117M235-CC-1-1_21.pdf</actes:NomFichier></actes:Annexe>
<actes:Annexe><actes:NomFichier>031-999100046-20170420-lmc117M235-CC-1-1_22.pdf</actes:NomFichier></actes:Annexe>
<actes:Annexe><actes:NomFichier>031-999100046-20170420-lmc117M235-CC-1-1_23.pdf</actes:NomFichier></actes:Annexe>
</actes:Annexes></actes:Acte>

(我删除了链接数据,但它们是正确的。)

这里是cURL发送的技术xml的一个例子:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v20="http://dev.cdcfast.fr/connecteur/V20">
<soapenv:Header/><soapenv:Body>
<v20:traiterACTES>
<v20:typeTraitement>TELETRANSMISSION</v20:typeTraitement>
<v20:DNUtilisateur>E = assistant@toulouse.fr, CN = Assistant TOULOUSE, OU = 0002 999100046, OU = FAST UTILISATEUR, O = CU TOULOUSE, L = TOULOUSE, C = FR</v20:DNUtilisateur>
<v20:SIREN>999100046</v20:SIREN>
<v20:fichierACTES>031-999100046-20170420-lmc116M244-CC-1-1_0.xml</v20:fichierACTES>
</v20:traiterACTES>
</soapenv:Body>
</soapenv:Envelope>

这是我在PHP中的cURL函数:

function cdcDemandeEnvoi($cheminFichierXML)
    {
        $ch = curl_init();

        $url_decoupe = explode("/", $cheminFichierXML);
        $fichierXML = end($url_decoupe);
        $nomFichierXML = pathinfo($fichierXML, PATHINFO_FILENAME);

        $urlPut = "https://recette.efast.fr/ascl/services/FASTConnecteur/".$nomFichierXML;
        $file = '@'.$cheminFichierXML;

        //Proxy config
        $proxyAdresse = "http://";
        $proxyIdentification = "";

        $header = array("Content-Type:text/plain; charset=UTF-8");
        $curl_post_data = array("file" => $file);

        curl_setopt($ch, CURLOPT_URL, $urlPut);
        curl_setopt($ch, CURLOPT_PROXY, $proxyAdresse);
        curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyIdentification);
        curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_NTLM);
        curl_setopt($ch, CURLOPT_USERAGENT, "curl/7.29.0");
        curl_setopt($ch, CURLOPT_SSLCERT, "/var/www/html/teletransmission/certificats/test/test.crt");  
        curl_setopt($ch, CURLOPT_SSLKEY, "/var/www/html/teletransmission/certificats/test/test.privkey"); 
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $curl_post_data);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE);

        $output = curl_exec($ch);
        $error = curl_error($ch);
        $http_code = curl_getinfo($ch ,CURLINFO_HTTP_CODE); 

        curl_close($ch);

    }

但是当我发送cURL请求时,我收到了他的消息错误:

soapenv:Receivercom.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character '-' (code 45) in prolog; expected '<'
 at [row,col {unknown-source}]: [1,1]org.apache.axis2.AxisFault: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character '-' (code 45) in prolog; expected '<'
 at [row,col {unknown-source}]: [1,1]
    at org.apache.axis2.AxisFault.makeFault(AxisFault.java:417)
    at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:283)
    at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:120)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.struts2.dispatcher.ActionContextCleanUp.doFilter(ActionContextCleanUp.java:102)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:567)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190)
    at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:291)
    at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:769)
    at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:698)
    at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:891)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.axiom.om.OMException: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character '-' (code 45) in prolog; expected '<'
 at [row,col {unknown-source}]: [1,1]
    at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:239)
    at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.getSOAPEnvelope(StAXSOAPModelBuilder.java:161)
    at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.<init>(StAXSOAPModelBuilder.java:110)
    at org.apache.axis2.builder.BuilderUtil.getSOAPBuilder(BuilderUtil.java:609)
    at org.apache.axis2.transport.TransportUtils.createDocumentElement(TransportUtils.java:178)
    at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:111)
    at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:270)
    ... 22 more
Caused by: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character '-' (code 45) in prolog; expected '<'
 at [row,col {unknown-source}]: [1,1]
    at com.ctc.wstx.sr.StreamScanner.throwUnexpectedChar(StreamScanner.java:639)
    at com.ctc.wstx.sr.BasicStreamReader.nextFromProlog(BasicStreamReader.java:2017)
    at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1102)
    at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:153)
    ... 28 more

所以我查看了webdav&amp;中的xml。我看到当我放入xml时,它在我的xml内容之前添加了这些行:

------------------------------1b9a7ef8734e
Content-Disposition: form-data; name="file"; filename="/mnt/test_dematmarche/depot/ACTES_17M235-PA-444/enveloppe1/031-999100046-20170420-lmc117M235-CC-1-1_0.xml"
Content-Type: application/octet-stream

&安培;这是在我的xml内容之后:

------------------------------1b9a7ef8734e--

我不明白我的问题在哪里。为什么要添加这些线? 有人可以帮我吗? 感谢

---编辑---

这是我将文件上传到webdav的函数:

function cdcDepotXML($fileActe)
    {

        $ch = curl_init();

        $url_decoupe = explode("/", $fileActe);
        $nomActe = end($url_decoupe);

        $urlPut = "https://url.fr/to/webdav/999100046/lmc1/".$nomActe;
        $file = '@'.$fileActe;

        $proxyAdresse = "http://proxyurl:80";
        $proxyIdentification = "proxyuser:proxypassword";

        $header = array("Content-Type:multipart/form-data");
        $curl_post_data = array("file" => $file);

        curl_setopt($ch, CURLOPT_URL, $urlPut);
        curl_setopt($ch, CURLOPT_PROXY, $proxyAdresse);
        curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyIdentification);
        curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_NTLM);
        curl_setopt($ch, CURLOPT_USERAGENT, "curl/7.29.0");
        curl_setopt($ch, CURLOPT_SSLCERT, "/var/www/html/teletransmission/certificats/test/test.crt");  
        curl_setopt($ch, CURLOPT_SSLKEY, "/var/www/html/teletransmission/certificats/test/test.privkey"); 
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
        curl_setopt($ch, CURLOPT_POSTFIELDS, $curl_post_data);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE);

        $output = curl_exec($ch);
        $error = curl_error($ch);
        $http_code = curl_getinfo($ch ,CURLINFO_HTTP_CODE); 

        curl_close($ch);

}

1 个答案:

答案 0 :(得分:0)

最后,我找到了解决方案!!

这是卷曲功能:

function cdcDepotXML($fileActe)
{

    $ch = curl_init();

    $url_decoupe = explode("/", $fileActe);
    $nomActe = end($url_decoupe);

    $urlPut = "https://url.fr/to/webdav/999100046/lmc1/".$nomActe;
    $file = '@'.$fileActe;

    $proxyAdresse = "http://proxyurl:80";
    $proxyIdentification = "proxyuser:proxypassword";

    $header = array("Content-Type:multipart/form-data");

    $fp = fopen($fileActe, 'r');

    curl_setopt($ch, CURLOPT_URL, $urlPut);
    curl_setopt($ch, CURLOPT_PROXY, $proxyAdresse);
    curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyIdentification);
    curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_NTLM);
    curl_setopt($ch, CURLOPT_USERAGENT, "curl/7.29.0");
    curl_setopt($ch, CURLOPT_SSLCERT, "/var/www/html/teletransmission/certificats/test/test.crt");  
    curl_setopt($ch, CURLOPT_SSLKEY, "/var/www/html/teletransmission/certificats/test/test.privkey"); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);      
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch,CURLOPT_HTTPGET, true);     
    curl_setopt($ch, CURLOPT_UPLOAD, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch, CURLOPT_INFILE, $fp);
    curl_setopt($ch, CURLOPT_INFILESIZE, filesize($fileActe));

    $output = curl_exec($ch);
    $error = curl_error($ch);
    $http_code = curl_getinfo($ch ,CURLINFO_HTTP_CODE); 

    print "erreur : " .$error ." " .$http_code;

    curl_close($ch);
}