菜鸟问个接口问题
求大神们给个详细的回复
我想做一个ashx的接口来接收别人post过来的json数据,怎么写?
最好就是连别人是怎么过来post过来的例子都有,我想看看是怎么交互的!!
[解决办法]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace WebApplication1
{
/// <summary>
/// Handler1 的摘要说明
/// </summary>
public class Handler1 : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
//string JsonData = context.Request.QueryString["Json"];
string JsonData = context.Request["Json"];
context.Response.ContentType = "text/plain";
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
//context.Response.Write("Hello World");
context.Response.Write(string.Format("你刚刚提交上来的数据:\n{0}", JsonData));
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
System.Collections.Specialized.NameValueCollection Data = new System.Collections.Specialized.NameValueCollection();
Data.Add("Json", "{"Name":"Tom","Age":"20"}"");
MessageBox.Show(Encoding.UTF8.GetString(new System.Net.WebClient().UploadValues("http://localhost:7240/Handler1.ashx", "POST", Data)));