用PHP发送HTTP POST 请求,获得返回结果。(转)

');
  }
  //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);
?>

你可能感兴趣的:(PHP,PHP)