News新闻

业界新闻动态、技术前沿
Who are we?

您的位置:首页      乐道系统FAQ      php利用fsockopen GET/POST提交表单及上传文件

php利用fsockopen GET/POST提交表单及上传文件

发布日期:2017-05-22 00:00:00 70

php利用fsockopen GET/POST提交表单及上传文件,具体内容如下

1.GET

get.php

<?php 
$host = 'demo.fdipzone.com'; 
$port = 80; 
$errno = ''; 
$errstr = ''; 
$timeout = 30; 
$url = '/socket/getapi.php'; 
 
$param = array( 
  'name' => 'fdipzone', 
  'gender' => 'man' 
); 
 
$url = $url.'?'.http_build_query($param); 
 
// create connect 
$fp = fsockopen($host, $port, $errno, $errstr, $timeout); 
 
if(!$fp){ 
  return false; 
} 
 
// send request 
$out = "GET ${url} HTTP/1.1\r\n"; 
$out .= "Host: ${host}\r\n"; 
$out .= "Connection:close\r\n\r\n"; 
 
fputs($fp, $out); 
 
// get response 
$response = ''; 
while($row=fread($fp, 4096)){ 
  $response .= $row; 
} 
 
fclose($fp); 
 
$pos = strpos($response, "\r\n\r\n"); 
$response = substr($response, $pos+4); 
 
echo $response; 
?>