分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 运营维护

http

发布时间:2023-09-06 02:30责任编辑:郭大石关键词: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

原文地址:https://www.cnblogs.com/niyl/p/10283476.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved