HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
myRequest.Method = "POST";//极光http请求方式为post
myRequest.Headers.Add("Authorization: " + common.StringHelper.EncodeBase64(ApiKey + ":" + APIMasterSecret));
myRequest.ContentType = "application/json; charset=utf-8";//按照极光的要求
myRequest.Accept = "application/json";
myRequest.ContentLength = data.Length;
Stream newStream = myRequest.GetRequestStream();
// Send the data.
newStream.Write(data, 0, data.Length);
newStream.Close();
// Get response
var response = (HttpWebResponse)myRequest.GetResponse();
using (var reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("UTF-8")))
{
string result = reader.ReadToEnd();
reader.Close();
response.Close();
return result;
}
按照极光推送的要求,拼好了header 但是提交老是400错误(参数错误)…然后本人用文档里的json数据来提交,心想这下不会是参数错了吧,结果还是400,那本人就怀疑是不是本人的post方法有问题啊…发上来让大家帮看看…假如有朋友做过的,请支援一下….谢谢
解决方案:30分
参数错误一般都指你的data有错,你需要把data和文档好好对照下
解决方案:10分
这类POST要想错还真不容易的,不过你要注意的就是假如有中文应该按他们要求处理,签名哪些字段也是有要求的,一般假如是报参数错,往往是用户粗心比较多