Php uses curl to simulate post request to submit xml
Php uses curl to simulate the xml submission of post requests (the interface on the Java server is requested) However, the request using httprequest in jsp can be successful. In JAVA, post data is processed in this way. After I use asXML () in php, it still cannot be solved. 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 the php Public function test (){ $ TestHost = 'http: // 127.0.0.1: 8080' $ Data =' George John Reminder Don't forget the meeting! '; $ 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; }
|