PHP技术现实HTTP提交POST事件

来源:互联网 发布:知乎 阿里 投资 编辑:程序博客网 时间:2024/05/22 09:39
 
本帖最后由 wcpsoft 于 2011-11-28 07:37 编辑

最近做项目,使用了HTTP请求POST提交XML事件,并返回数据的程序。现在我就和大家分享一下。
set_time_limit(0);
include 'conf.php';
$filename = "234.XML";
$file = fopen($filename,"r");
$filesize = filesize($filename);
$body = fread($file,$filesize);  //将XML读出保存到$body变量中
$http_url="http://127.0.0.1:8888/AdapterInboundPoint";  //定义请求地址
   $post_header[]="POST  $http_url HTTP/1.1";                   //根据实际需要编写请求header
    $post_header[]="hai.method:test";
    $post_header[]="hai.targetLogicApp:test.PL.0";
    $post_header[]="hai.targetLogicService:test";
    $post_header[] ="hai.sourceLogicApp:test.TEST.HXZ";
    $post_header[] ="Content-Type:text/html; charset=utf-8";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $http_url);                             //连接地址
  curl_setopt($ch, CURLOPT_HTTPHEADER, $post_header);   //发送头
curl_setopt($ch, CURLOPT_POST, 1);                                    
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);                 //传送XML
curl_setopt($ch, CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_NOBODY,0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);                                                   //返回结果
$info = curl_getinfo($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);         //返回状态码
curl_close($ch);
echo $info['url'] . ''. $info['total_time'] . ''.''.$code.'<br/>';
echo '<br/><font color="#FF0000">'.$data.'</font><br/>';
原创粉丝点击