邮报看起来像这样。
$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/
答案 0 :(得分:3)
将您的数据转换为URL编码的字符串:
$params = array('http' => array('method' => 'POST', 'content' => http_build_query($data)) );
答案 1 :(得分:0)
我没有看到你使用http_build_query
编码POST的数据,也没有手动编码。如果不这样做,您需要在目标端读取原始请求内容并手动解析: - )
答案 2 :(得分:0)
您的数据变量似乎使用了错误的格式。在PHP手册页上查看this comment