最简单的服务端接收参数方法:
public void ProcessRequest(HttpContext context)
{
// Post方式下,取得client端传过来的数据
if ("post".Equals(context.Request.HttpMethod.ToLower()))
{
StreamReader reader = new StreamReader(context.Request.InputStream);
string json = HttpUtility.UrlDecode(reader.ReadToEnd());
context.Response.Write(json);
}
// Get方式下,取得client端传过来的数据
else
{
// 注意,这个是需要解码的
string json = HttpUtility.UrlDecode(context.Request.QueryString.ToString());
context.Response.Write(json);
}
}
客户端:一般模拟http发送请求。
坑点:读取InputStream后再读取一遍,此时再去读取InputStream,是空...空