Home  >  Article  >  php教程  >  PHP CURL模拟POST提交XML数据

PHP CURL模拟POST提交XML数据

WBOY
WBOYOriginal
2016-06-13 11:27:381067browse

本文章来给大家介绍一个利用PHP CURL模拟POST提交XML数据,因为接受方只接受xml数据所以我就写了一个,下面分享给各位朋友,有需要的朋友可参考。

 代码如下 复制代码


$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);//关闭

再来介绍一个POST表单提交的案例

 代码如下 复制代码

//首先要引用这个类
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);


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn