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
  • 相关阅读:
    在网络中传输数据(I)
    WinForm DataGrid 中在 DataGridBoolColumn 的列标题上加一个 CheckBox 实现全选和全不选
    datagrid 相关
    Agile Framework视频演示发布
    asp.net(含:模拟登陆,照片列表)
    会计电算化常考题目一
    jquery实例教学一
    ASP .net(照片列表详细功能CRUD演示)
    会计电算化常考题目
    ASP.NET(get和post比较)
  • 原文地址:https://www.cnblogs.com/niyl/p/10283476.html
Copyright © 2011-2022 走看看