PHPCURL simulates POST to submit XML data _ PHP Tutorial

Source: Internet
Author: User
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...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.