zoukankan      html  css  js  c++  java
  • http

     #region 获取wishpost的token和refresh_token
            /// <summary>
            /// 获取wishpost的token和refresh_token
            /// </summary>
            /// <param name="code">授权码</param>
            /// <returns>返回收到的结果</returns>
            public string wishpost_gettoken(string code)
            {
                string htmlStr = string.Empty;
    
                try
                {
                    string url = "https://wishpost.wish.com/api/v3/access_token";
                    string authorization_str = "Basic {123123123123123}";
                    string redirect_uri = "https://wishpost.corp.contextlogic.com/"; //表示重定向URI
                    string client_id = "12345678"; //表示客户端ID
    
                    string strPostdata = "grant_type=authorization_code&redirect_uri=" + redirect_uri + "&client_id=" + client_id + "&code=" + code;
                    Encoding encoding = Encoding.UTF8;
    
    
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
    
                    request.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
                    request.Headers.Add("Authorization", authorization_str);
                    request.AllowAutoRedirect = true;
                    request.Method = "POST";
    
    
                    byte[] buffer = encoding.GetBytes(strPostdata);
    
                    request.ContentLength = buffer.Length;
                    request.GetRequestStream().Write(buffer, 0, buffer.Length);
    
                    //获取当前Http请求的响应实例
                    HttpWebResponse response = request.GetResponse() as HttpWebResponse;
                    Stream responseStream = response.GetResponseStream();
    
                    using (StreamReader reader = new StreamReader(responseStream, Encoding.GetEncoding("UTF-8")))
                    {
                        htmlStr = reader.ReadToEnd();
                    }
    
                    responseStream.Close();
                }
                catch (WebException ex)
                {
    
                    HttpWebResponse res = (HttpWebResponse)ex.Response;
                    StreamReader sr = new StreamReader(res.GetResponseStream(), Encoding.GetEncoding("UTF-8"));
                    htmlStr = sr.ReadToEnd();
                    sr.Close();
                }
                return htmlStr;
                
            }
            #endregion
  • 相关阅读:
    hdu 4508
    hdu 4506
    hdu 4505
    hdu 1525
    hdu 2212
    (贪心)删数问题
    (最短路 Dijkstra) hdu 1544
    (次小生成树) poj 1679
    (prim)hdu 1102
    (kruskal)hdu 1863
  • 原文地址:https://www.cnblogs.com/niyl/p/10283476.html
Copyright © 2011-2022 走看看