手机端发送POST到我的ASP.net ASP.net 程序接收不到参数
我现在要做一个asp.net 的消息推送GCM。手机端的程序不是.net做的,我只负责写.net 的这个接口,现在手机端的程序POST一个请求到我的asp.net 服务端,把注册ID等一些参数用json格式数据传到asp.net这服务端。 然后我这服务端用
byte[] byts = new byte[Request.InputStream.Length];
Request.InputStream.Read(byts, 0, byts.Length);
string req = System.Text.Encoding.Default.GetString(byts);
req = Server.UrlDecode(req);
接收,但是我这边一直接收不到数据。手机端监控到我这边出现500错误。
另外添加解释一下:我在本机做了测试,本机建了两个站点,一个站点向另一个站点发送数据和接收数据都没有问题。
-----------------------发送请求的页面代码--------------------------------
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://172.16.120.154:8012/GCM/Default.aspx");
request.Method = "POST";
request.ContentType = "application/json;charset=utf-8;";
request.Headers.Add(string.Format("Authorization: key={0}", "AIzaSyCTwfwpilED77oUutYrFjam-oQdLiHRBLo"));
string RegistrationID = "fdsafdsafea";
string message1 = "Hello world";
var postData =
new
{
data = new
{
message = message1 //message這個tag要讓前端開發人員知道
},
registration_ids = new string[] { RegistrationID }
};
string p = JavaScriptConvert.SerializeObject(postData);//JsonConvert.SerializeObject(postData);//將Linq to json轉為字串
byte[] byteArray = Encoding.UTF8.GetBytes(p);//要發送的字串轉為byte[]
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
//接收反馈
WebResponse response = request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);