Home >Backend Development >PHP Tutorial >PHP CURL simulates POST to submit XML data_PHP tutorial
This article will introduce to you a way to use PHP CURL to simulate POST to submit XML data. Because the recipient only accepts xml data, I wrote one. I will share it with friends below. Friends in need can refer to it.
The code is as follows
|
Copy code
|
||||
$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); / /Define form submission address curl_setopt($ch, CURLOPT_POST, 1); //Define submission type 1: POST; 0: GET curl_setopt($ch, CURLOPT_HEADER, 1); //Define whether to display Status header 1: displayed; 0: not displayed curl_setopt($ch, CURLOPT_HTTPHEADER, $header);//Define the request type curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);//Define whether to output directly Return stream curl_setopt($ch, CURLOPT_POSTFIELDS, $data); //Define the submitted data, here is the XML file curl_close($ch);//Close |
The code is as follows |