Home > Backend Development > PHP Tutorial > PHP uses curl to simulate post request to submit xml

PHP uses curl to simulate post request to submit xml

WBOY
Release: 2016-07-25 08:46:52
Original
1361 people have browsed it
PHP uses curl to simulate post request submission xml (the request is the interface on the Java server)
But using httprequest to request in jsp can be successful
Post data is processed in this way in JAVA. Similarly, I still can’t solve it after using asXML() in PHP
Element r=rootEle.element("hmac");
r.setText(signMessage);
result.put("xml",xml);
Document.setXMLEncoding("GBK");
System.out.println("Complete xml request message:"+document.asXML());


Below is php
Public function test(){
$testHost = 'http://127.0.0.1:8080'
$data=' George< /to>                          $response=$this->sendPost($textHost,$data);
                           echo ($response);
                                                   }
         protected function sendPost($url,$data){
                $curl = curl_init();
​ ​ ​ ​ curl_setopt($curl, CURLOPT_URL, $url);
​ ​ ​ ​ curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
​ ​ ​ ​ curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
                  if (!empty($data)){
                      curl_setopt($curl, CURLOPT_POST, 1);
                    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
              }
​ ​ ​ ​ curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
                $output = curl_exec($curl);
                  curl_close($curl);
                    return $output;
        }



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template