[英]Sending Request via Postman works fine but not via angular client
my Setup:我的设置:
Web-API implemented in .Net Core 3.1.在 .Net Core 3.1 中实现的 Web-API。
Angular12 Frontend. Angular12 前端。
My API has an Endpoint that, when requested with the email address of user, searches in my Active Directory and returns the fullName of that user.我的API有一个端点,当在我的Active Directory用户,搜索电子邮件地址,并返回该用户的全名要求。 Then I want to display that name in a component in angular.
然后我想在 angular 的组件中显示该名称。
It works perfectly with Postman , I get the name of the user as text它与Postman完美配合,我以文本形式获取用户名
As you can see there are no custom headers and no query params attached to that Get Request that I make.如您所见,没有自定义标头,也没有附加到我创建的 Get 请求的查询参数。
So I thought I could implement the same in angular.所以我想我可以在 angular 中实现同样的功能。 I added:
我补充说:
getFullName() {
this.http.get<string>('https://localhost:44316/api/ADInfo/maid.sabanovic@gws.ms').subscribe(Response => {
this.fullName = Response;
console.log(this.fullName);
});
}
And I get:我得到:
Also the FullName Variable is undefined全名变量也未定义
Are there big Differences when sending Requests via Postman and via Angular?通过 Postman 和 Angular 发送请求时是否有很大的不同? Do I need to add headers to my request?
我需要在我的请求中添加标头吗?
In order to return Non-Json data, you need to pass {responseType: 'text'} in your request header.为了返回非 Json 数据,您需要在请求标头中传递 {responseType: 'text'}。
getFullName() {
this.http.get<string>('https://localhost:44316/api/ADInfo/maid.sabanovic@gws.ms', {responseType: 'text'}).subscribe(Response => {
this.fullName = Response;
console.log(this.fullName);
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.