如调用某一系统token信息
- controller获取token信息方法
[HttpPost("UpdatA")] [AllowAnonymous] public async Task<WebApiResult> UpdateA([FromBody] XXRequest request) { string _auth = HttpContext.Request.Headers["Authorization"]; ... }
- 在service调用时,使用token
private readonly HttpClient _httpclient; public XXProxy(HttpClient httpClient ) { _httpclient = httpClient; }
public async Task<WebApiResult> UpdateA(Demo request, string token) { _httpclient.DefaultRequestHeaders.Add("Authorization", token); HttpContent postContent = new StringContent(JsonConvert.SerializeObject(request)); postContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); ... }