码迷,mamicode.com
首页 > Web开发 > 详细

HP发送HTTP POST请求 返回结果

时间:2015-01-25 16:26:14      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:

HP发送HTTP POST请求 返回结果  

<?php

$srv_ip = ‘192.168.10.188‘;//你的目标服务地址或频道.
$srv_port = 80;
$url = ‘/demo/test_query_string.php‘; //接收你post的URL具体地址
$fp = ‘‘;
$resp_str = ‘‘;
$errno = 0;
$errstr = ‘‘;
$timeout = 10;
$post_str = "username=demo&str=aaaa";//要提交的内容.

//echo $url_str;
if ($srv_ip == ‘‘ || $dest_url == ‘‘){
echo(‘ip or dest url empty<br>‘);
}
//echo($srv_ip);
$fp = fsockopen($srv_ip,$srv_port,$errno,$errstr,$timeout);
if (!$fp){
echo(‘fp fail‘);
}
$content_length = strlen($post_str);
$post_header = "POST $url HTTP/1.1\r\n";
$post_header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$post_header .= "User-Agent: MSIE\r\n";
$post_header .= "Host: ".$srv_ip."\r\n";
$post_header .= "Content-Length: ".$content_length."\r\n";
$post_header .= "Connection: close\r\n\r\n";
$post_header .= $post_str."\r\n\r\n";
fwrite($fp,$post_header);
while(!feof($fp)){
$resp_str .= fgets($fp,512);//返回值放入$resp_str
}
fclose($fp);
echo($resp_str);//处理返回值.
//unset ($resp_str);
?>

HP发送HTTP POST请求 返回结果

标签:

原文地址:http://www.cnblogs.com/lykbk/p/werwerwe4354534.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!