所以标题是自我描述的。这是我的php代码
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 '
即没有参数值,我读了一个类似的帖子,我得到的想法是,也许你需要设置不同的上下文类型来传递内容参数。但是通过 php 文档查看,我没有找到任何用于设置上下文类型的选项http://php.net/manual/en/context.http.php
任何帮助都会很棒,谢谢