所以標題是自我描述性的。這裏是我的PHP代碼從PHP到HTTP處理程序做一個HTTP POST
function do_post_request($url, $data, $optional_headers = null)
{
$url = 'http://localhost:1181/WebSite1/PostHandler.ashx';
$data = array('fprm' => 1, 'sprm'=> 2, 'tprm'=>3
);
$params = array('http' => array(
'method' => 'POST',
'content' => $data
));
//$params = array('method'=>'POST', 'content'=>$data);
/* if ($optional_headers !== null) {
$params['http']['header'] = $optional_headers;
}*/
$ctx = stream_context_create($params);
//stream_context_set_option()
//debug($params);
//die();
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) {
throw new Exception("Problem with $url, $php_errormsg");
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $url, $php_errormsg");
}
return $response;
}
,這裏是我的處理代碼:
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string responseStr = "Hello World, this reply is from .net";
string fprm = context.Request["fprm"];
string sprm = context.Request["sprm"];
string tprm = context.Request["tprm"];
context.Response.Write(responseStr + " " + fprm + " " + sprm + " " + tprm);
}
,這是我收到的回覆:
'Hello World, this reply is from .net '
即不帶參數的值,我讀一個similar post和我得到的想法是,也許你需要設置不同的上下文類型來傳遞內容參數。但看throught PHP文檔,我不找任何選項,http://php.net/manual/en/context.http.php,用於設置上下文類型
任何幫助將是巨大的,感謝
header(content-type:你的內容類型在這裏); –