HTTP

  PHP POST



  
/* 
 他のURLにPOSTでアクセスする 
*/ 
$port=80; 
$host ="www.xxxx.jp"; 
$url ="cgi-bin/test.cgi"; 
$parm =”userid=$PHP_AUTH_USER”; //POSTで送る値 
$results=Get_Contents($host, $port,$url,$parm); 

function Get_Contents($host,$port,$url,$parm) { 
$line=""; 
$fp = fsockopen ($host, $port, $errno, $errstr, 30); 
if (!$fp) { 
     $line="socket: get error"; 
} else { 
$len=strlen($parm); 
     fputs ($fp, "POST /$url HTTP/1.0\nContent-length: $len\n\n$parm\n"); 
     while (!feof($fp)) { 
         $line .= fgets ($fp,1024); 
     } 
     fclose ($fp); 
} 
retrun $line; 
  

  
<?

// http.inc by nf@bigpond.net.au
// http://nf.wh3rd.net/

function http_post($server, $port, $url, $vars) {

// example:
//  http_post(
//	"www.fat.com",
//	80, 
//	"/weightloss.pl", 
//	array("name" => "obese bob", "age" => "20")
//	);

	$user_agent = "Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)";


	$urlencoded = "";
	while (list($key,$value) = each($vars))
		$urlencoded.= urlencode($key) . "=" . urlencode($value) . "&";
	$urlencoded = substr($urlencoded,0,-1);	

	$content_length = strlen($urlencoded);

	$headers = "POST $url HTTP/1.1
Accept: */*
Accept-Language: en-au
Content-Type: application/x-www-form-urlencoded
User-Agent: $user_agent
Host: $server
Connection: Keep-Alive
Cache-Control: no-cache
Content-Length: $content_length

";
	
	$fp = fsockopen($server, $port, $errno, $errstr);
	if (!$fp) {
		return false;
	}

	fputs($fp, $headers);
	fputs($fp, $urlencoded);
	
	$ret = "";
	while (!feof($fp))
		$ret.= fgets($fp, 1024);
        
	fclose($fp);
	
	return $ret;

}

  










  infoboard   管理者用   
このエントリーをはてなブックマークに追加





フリーフォントWEBサービス
SQLの窓WEBサービス

SQLの窓フリーソフト

素材

一般WEBツールリンク

SQLの窓

フリーソフト

JSライブラリ