zoukankan      html  css  js  c++  java
  • 淘宝开发平台获取access_token(sessionkey)

    C#代码:

     public HttpResponseMessage GetAccessToken(string code,string appkey, string appsecret)
            {
                WebUtils webUtils = new WebUtils();
                IDictionary<string, string> param = new Dictionary<string, string>();
                string url = "https://oauth.taobao.com/token";
                string responseMsg = "";
                try
                {
                    param.Add("grant_type", "authorization_code");
                    param.Add("code", code);
                    param.Add("client_id", appkey);
                    param.Add("client_secret", appsecret);
                    param.Add("redirect_uri", "");
                    param.Add("view", "web");
                    string response = webUtils.DoPost(url, param,null);
                    CacheManager.Put("AccessToken", response, new TimeSpan(1, 0, 0));
                    responseMsg = "操作成功";
                }
                catch (Exception)
                {
                    responseMsg = "操作失败";
                }
    
                return new HttpResponseMessage
                {
                    Content = new StringContent(responseMsg, Encoding.UTF8, "application/xml")
                };
            }

    post方法:
     public string DoPost(string url, IDictionary<string, string> textParams, IDictionary<string, string> headerParams)
            {
                HttpWebRequest req = GetWebRequest(url, "POST", headerParams);
                req.ContentType = "application/x-www-form-urlencoded;charset=utf-8";
    
                byte[] postData = Encoding.UTF8.GetBytes(BuildQuery(textParams));
                System.IO.Stream reqStream = req.GetRequestStream();
                reqStream.Write(postData, 0, postData.Length);
                reqStream.Close();
    
                HttpWebResponse rsp = (HttpWebResponse)req.GetResponse();
                Encoding encoding = GetResponseEncoding(rsp);
                return GetResponseAsString(rsp, encoding);
            }
     
  • 相关阅读:
    Servlet----------在 Servlet 中的xml配置
    java连接数据库时的报错
    借用HTML5 插入视频。音频
    多线程的总结
    穷举法例子
    利用递归求最大公约数和最小公倍数
    递归逆序的使用
    Mac OS X运行程序出现bad interpreter: operation not permitted的解决方案
    C#之枚举类型
    窗体的单例模式
  • 原文地址:https://www.cnblogs.com/FollowWinds/p/8745579.html
Copyright © 2011-2022 走看看