php发送post数据 phppost
php语言,用服务器发送一个post请求怎么写?比如往百度首页发送post数据(a=1&b=2)
function POST($Url,$Argv){
创新互联-专业网站定制、快速模板网站建设、高性价比梁溪网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式梁溪网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖梁溪地区。费用合理售后完善,10多年实体公司更值得信赖。
$flag = 0;
$post = '';
$errno = '';
$errstr = '';
foreach($Argv as $key = $value){
if($flag != 0){
$post .= "";
$flag = 1;
}
$post .= $key . "=";
$post .= urlencode($value);
$flag = 1;
}
$length = strlen($post);
$fp = fsockopen("localhost",80,$errno,$errstr,10) or exit($errstr."---".$errno);
$header = "POST " . $Url . " HTTP/1.1\r\n";
$header .= "Host:127.0.0.1\r\n";
$header .= "Referer:/flandy/post.php\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . $length . "\r\n";
$header .= "Connection: Close\r\n\r\n";
$header .= $post . "\r\n";
fputs($fp,$header);
$inheader = 1;
$Return = '';
while(!feof($fp)){
$line = fgets($fp,1024);
if($inheader ($line == "\n" || $line == "\r\n"))$inheader = 0;
if($inheader == 0) $Return .= $line;
}
fclose($fp);
return trim($Return);
}
//调用方式
$Result = POST('xxxxxURLxxx',array('dataName' = 'dataValue'));
PHP怎么发送带cookie的POST数据
譬如cookie 名为 mycookie。
直接变量获取 $_COOKIE['mycookie']) 然后像普通数据一样提交。
希望回答对你有帮助,如果有疑问,请继续追问
答题不易,互相理解,您的采纳是我前进的动力,感谢您。
PHP 模拟HTTP发送POST请求
用php模拟登陆主要分为三部分1. post数据。2.根据返回的http头,从中截出cookie段。3.伪造http头发送请求。 我这里以用php抓取163相册的需要密码才能访问的目录为例。?phpfunction posttohost($url, $data) //post数据if (!isset($url['query'])) $encoded = "";foreach ($data as $k=$v) $fp = fsockopen($url['host'], $url['port'] ? $url['port'] : 80);if (!$fp) return "Failed to open socket to $url[host]";fputs($fp, sprintf("POST %s%s%s HTTP/1.0\n", $url['path'], $url['query'] ? "?" : "", $url['query']));fputs($fp, "Host: $url[host]\n");fputs($fp, "Content-type: application/x-www-form-urlencoded\n");fputs($fp, "Content-length: " . strlen($encoded) . "\n");fputs($fp, "Connection: close\n\n");fputs($fp, "$encoded\n");$line = fgets($fp,1024);if (!eregi("^HTTP/1\.. 200", $line)) return;$results = ""; $inheader = 1;while(!feof($fp)) elseif ($inheader) }fclose($fp);return $results;} 答案补充 function getjs($juser,$jaid,$jcookie) //伪造http头 答案补充 else fclose( $socket ); return $ret;}}$iurl=' '.$iuser.'/'.$aid.'/';$idata=array ('pass'=$pass,'checking'='1'); //通过winsock抓包发现,输入访问密码,会向163相册发送 pass=密码checking=1$mystr=posttohost($iurl,$idata);$pattern='/HALFORDER=(.*?);/';preg_match($pattern,$mystr,$out);$str=getjs($iuser,$aid,$out[1]);echo $str;?
文章题目:php发送post数据 phppost
标题来源:http://pwwzsj.com/article/ddjcjjd.html