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 代码如下 | 复制代码 | $url = "http://www.bkjia.com/ login"; $ch = curl_init(); $header[] = "Content-type: text/xml";//定义content-type为xml curl_setopt($ch, CURLOPT_URL, $url); //定义表单提交地址 curl_setopt($ch, CURLOPT_POST, 1); //定义提交类型 1:POST ;0:GET curl_setopt($ch, CURLOPT_HEADER, 1); //定义是否显示状态头 1:显示 ; 0:不显示 curl_setopt($ch, CURLOPT_HTTPHEADER, $header);//定义请求类型 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);//定义是否直接输出返回流 curl_setopt($ch, CURLOPT_POSTFIELDS, $data); //定义提交的数据,这里是XML文件 curl_close($ch);//关闭
| |
Copy code |
代码如下 | 复制代码 | //首先要引用这个类 include("/data/tools/pooy/Snoopy/Snoopy.class.php"); $snoopy = new Snoopy; //$Parameters这个是要提交的数组 $Parameters["username"] = "user"; $Parameters["pass"] = "pass"; $file = "/test/test.jpg"; $serviceUrl = "http://www.test.com/fileProcess.php"; $postfiles["image"] = $file; //$filename上传文件相对路径 例如"upload/taoav.jpg";image/jpg $snoopy->_submit_type = "multipart/form-data"; //设定submit类型 $snoopy->submit($serviceUrl,$Parameters,$postfiles); |
$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 |
Let’s introduce another case of POST form submission
The code is as follows | Copy code |
//First reference this class include("/data/tools/pooy/Snoopy/Snoopy.class.php" ); $snoopy = new Snoopy; //$Parameters is 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 relative path to upload file such as "upload/taoav.jpg";image/jpg $snoopy->_submit_type = "multipart/form-data" ; //Set the submit type $snoopy->submit($serviceUrl,$Parameters,$postfiles);
http://www.bkjia.com/PHPjc/444618.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/444618.htmlTechArticleThis 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 just wrote one and share it with all my friends who are in need...
|