Php curl simulates POST to submit XML data

Source: Internet
Author: User

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 );


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.