PHPCURL simulates POST to submit XML data. This article describes how to use PHPCURL to simulate POST to submit XML data. because the receiver only accepts xml data, I wrote one. I will share it with you, A friend who needs this article will introduce you to submitting XML data using php curl to simulate POST. because the recipient only accepts xml data, I wrote one. I will share it with you below, for more information, see.
The code is as follows: |
|
$ Url = "http://www.bkjia.com/login "; $ 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: |
|
// 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 ); |
CURL simulates POST to submit XML data, because the receiver only accepts xml data, so I wrote one. I will share it with you, friends who need it...