c#生成token访问的接口_c#调用微信接口获取token值

本文介绍了一个使用C#实现的获取微信接口访问token的方法。通过设置URL(包含appid和AppSecret)并发送HTTP请求,从响应中读取并返回token值。
摘要由CSDN通过智能技术生成

废话不说,一个方法实现,这里的url 参数即为配置好的访问路径,

string url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + AppID + "&secret=" + AppSecret;

这里的两个参数AppID、AppSecret对应微信公众账号

public static string GetPage(string url )

{

Stream instream = null;

StreamReader sr = null;

HttpWebResponse response = null;

HttpWebRequest request = null;

Encoding encoding = Encoding.UTF8;

// 准备请求...

try

{

// 设置参数

request = WebRequest.Create(posturl) as HttpWebRequest;

CookieContainer cookieContainer = new CookieContainer();

request.CookieContainer = cookieContainer;

request.AllowAutoRedirect = true;

request.Method = "POST";

//发送请求并获取相应回应数据

response 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值