码迷,mamicode.com
首页 > Windows程序 > 详细

c# 调用 友盟api

时间:2014-11-13 20:33:21      阅读:287      评论:0      收藏:0      [点我收藏+]

标签:des   blog   http   io   ar   os   使用   sp   div   

今天要使用友盟的推送API来给我的app进行推送信息,调试了好久,老是返回500错误,最终在友盟的技术人员支持下完成了此操作,在此多谢友盟技术和客服人员。

把发方法和注意事项贴出来供大家参考。

 

public static void post5()
        {
            string url = "http://msg.umeng.com/api/send";
            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
            request.Method = "POST";
            string str = "{\"appKey\":\"***\",\"timestamp\":1415872474403,\"validation_token\":\"***\",\"type\":\"broadcast\",\"payload\":{\"aps\":{ \"alert\":\"xxx\"}},\"policy\":{},\"production_mode\":\"false\",\"description\":\"xxx\"}";
            
            byte[] bs = Encoding.ASCII.GetBytes(str);
            request.ContentLength = bs.Length;
            using (Stream reqStream = request.GetRequestStream())
            {
                reqStream.Write(bs, 0, bs.Length);
                reqStream.Close();
            }
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            HttpStatusCode statusCode = response.StatusCode;
        }

  注意:传内容时别忘记值得内容加引号,大家在传入appkey timestamp 的时候习惯传参,容易忽略引号。

 

贴出此列:

 {"appKey":"123456","timestamp":1415872474403,"validation_token":"896415454sdfd","type":"broadcast","payload":{"aps":{ "alert":"xxx"}},"policy":{},"production_mode":"false","description":"xxx"} 

 

c# 调用 友盟api

标签:des   blog   http   io   ar   os   使用   sp   div   

原文地址:http://www.cnblogs.com/long11310/p/4095641.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!