The Post看起來像這樣。
$data = array('icd9' => $icd9, 'cpt' => $cpt, 'session_id'=> $session_id);
$url = $api_location."rarity/".$session_id;
$params = array('http' => array('method' => 'POST', 'content' => $data));
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp){
return "Error";
}
$response = @stream_get_contents($fp);
$results = $response;//json_decode($response);
return $results;
的api_location服務器上的座看起來是這樣的:
if ($_POST['session_id']){
$fh = fopen('/interaction/rarity_req/alive.txt','w');
fwrite($fh,'\r\n'.date("Y-m-d - H:i:s"));
fclose($fh);
$session_id = $_POST['session_id'];
$cpt = $_POST['cpt'];
$icd9 = $_POST['icd9'];
}else{
$fh = fopen('/interaction/rarity_req/died.txt','w');
fwrite($fh, '\r\n'.date("Y-m-d - H:i:s"));
fclose($fh);
}
什麼想法?我知道我可以安裝cURL來做到這一點,但是儘可能地避免它,因爲這很簡單。在立足它關閉這個博客帖子的:http://wezfurlong.org/blog/2006/nov/http-post-from-php-without-curl/
真棒就是這樣。我會在2分鐘內接受這個答案。 – DiscontentDisciple 2012-02-09 21:14:45