http
Posted niyl
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
以上是关于http的主要内容,如果未能解决你的问题,请参考以下文章
Flutter 报错 DioError [DioErrorType.DEFAULT]: Bad state: Insecure HTTP is not allowed by platform(代码片段