[英]C#: How to htttps get request with bearer token in header
Hello everyone my name is Taniguchi.大家好,我的名字是谷口。
I've tried retrieving an entity from Dynamics 365 Finance and Operations and i did it on postman but now i having difficulties in asp.net core I was able to get the token but when i try to retrieve the entity the response gives me a html and this html leads me to the Dynamics 365 Finance and Operations Page.我尝试从 Dynamics 365 Finance and Operations 中检索实体,我在 postman 上进行了操作,但现在我在 asp.net 核心中遇到了困难html 将我带到 Dynamics 365 Finance and Operations 页面。 My code: `
我的代码:`
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
const string environmentsUri = "https://trial-0z4qfj.sandbox.operations.dynamics.com/data/PartyContacts";
var response = httpClient.GetAsync(environmentsUri).Result;
var content = response.Content.ReadAsStringAsync().Result;
what am i doing wrong?我究竟做错了什么? do i need to authenticate again?
我需要再次认证吗?
I suspect the Token you receive is not correct/complete.我怀疑您收到的令牌不正确/不完整。 I remember I faced the similar issue, I would request you to follow this blog post and try to receive Token as shown This shall help you solve your issue.
我记得我遇到过类似的问题,我会要求您关注这篇博文并尝试接收如图所示的令牌这将帮助您解决您的问题。
In addition I would recommend you use Organizaiton service with Webapi/Access Token.此外,我建议您使用带有 Webapi/Access Token 的 Organizaiton 服务。 It will give you native library usage and you could query crm easily.
它将为您提供本机库的使用,您可以轻松查询 crm。
Seems like you are only using the parameter accessToken
instead of the variable value.好像您只使用参数
accessToken
而不是变量值。 Depends on how you declared accessToken
ofc.取决于您如何声明
accessToken
ofc。 The rest seems fine. rest 看起来不错。
Try:尝试:
httpClient.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", token.accessToken);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.