This article describes how to use php curl to simulate POST to submit XML data. Because the receiver only accepts xml data, I wrote one. I will share it with you, for more information, see.
| The Code is as follows: |
Copy code |
$ Url = "http://www.bkjia.com/login "; <! --? Xml version = "1.0 "? --> $ Ch = curl_init (); $ Header [] = "Content-type: text/xml"; // define content-type as xml Curl_setopt ($ ch, CURLOPT_URL, $ url); // defines the form submission address Curl_setopt ($ ch, CURLOPT_POST, 1); // defines the submission type 1: POST; 0: GET Curl_setopt ($ ch, CURLOPT_HEADER, 1); // defines whether to display status header 1: display; 0: Not Display Curl_setopt ($ ch, CURLOPT_HTTPHEADER, $ header); // define the request type Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 0); // you can specify whether to directly output the returned stream. Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ data); // defines the submitted data, which is an XML file. Curl_close ($ ch); // close
|
Next we will introduce a case of POST form submission.
| The Code is as follows: |
Copy code |
// Reference this class first Include ("/data/tools/pooy/Snoopy. class. php "); $ Snoopy = new Snoopy; // $ Parameters: the array to be submitted $ Parameters ["username"] = "user "; $ Parameters ["pass"] = "pass "; $ File = "/test/test.jpg "; $ ServiceUrl = "http://www.test.com/fileProcess.php "; $ Postfiles ["image"] = $ file; // $ filename: The relative path of the uploaded file, for example, "upload/taoav.jpg"; image/jpg $ Snoopy-> _ submit_type = "multipart/form-data"; // you can specify the submit type. $ Snoopy-> submit ($ serviceUrl, $ Parameters, $ postfiles ); |