.net core httpget请求,获取数据


private readonly IHttpClientFactory _clientFactory;  注入进来

public async Task<WxUserInfoDto> CreateAsync(CreateWxUserInfoDto input)
{

string appid = "321";
string appsecret = "123";
string code = "12341erw34312";//随便写一个

//
var request = new HttpRequestMessage(HttpMethod.Get,
"https://api.weixin.qq.com/sns/jscode2session?appid="+appid+"&secret="+appsecret+"&js_code="+code+"&grant_type=authorization_code");
request.Headers.Add("Accept", "application/vnd.github.v3+json");
request.Headers.Add("User-Agent", "HttpClientFactory-Sample");

var client = _clientFactory.CreateClient();
var response = await client.SendAsync(request);
var content = response.Content;
var wxResult = content.ReadAsStringAsync().Result; //获取返回结果


}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM