码迷,mamicode.com
首页 > 微信 > 详细

c#调用微信接口获取token值

时间:2015-08-27 18:19:43      阅读:282      评论:0      收藏:0      [点我收藏+]

标签:

废话不说,一个方法实现,这里的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 = request.GetResponse() as HttpWebResponse;
//直到request.GetResponse()程序才开始向目标网页发送Post请求
instream = response.GetResponseStream();
sr = new StreamReader(instream, encoding);
//返回结果网页(html)代码
string content = sr.ReadToEnd();
Logs.WriteLog("" + DateTime.Now + content);  //记录返回结果
return content;
}
catch (Exception ex)
{
string err = ex.Message;
return string.Empty;
}
}

c#调用微信接口获取token值

标签:

原文地址:http://www.cnblogs.com/ZQiuMei/p/4763770.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!