2008年6月26日 星期四

[php]不使用 form 之下傳送 POST 變數

方法一:
-----------------------------------------------------------------

$ReqHeader ="POST $URI HTTP/1.1n"."Host: $Hostn".

"Content-Type: application/x-www-form-urlencodedn".

"Content-Length: $ContentLengthnn".

"$ReqBodyn";


// Open the connection to the host

$socket = fsockopen($Host, 80, &$errno, &$errstr);

if (!$socket){

$Result["errno"] = $errno;

$Result["errstr"] = $errstr;

return $Result;

}

$idx = 0;

fputs($socket, $ReqHeader);

while (!feof($socket)){

$Result[$idx++] = fgets($socket, 128);

}
------------------------------------------------------
方法二:
------------------------------------------------------
$URL="www.mysite.com/test.php";

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"https://$URL");

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, "Data1=blah&Data2=blah");

curl_exec ($ch);

curl_close ($ch);

------------------------------------------------------

【下列文章您可能也有興趣】

沒有留言: