简体   繁体   English

通过 Postman 发送请求工作正常,但不能通过 Angular 客户端

[英]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.

相关问题 POST 请求被本地 Angular 应用程序的 CORS 策略阻止,但在 Postman 和 Thunder Client 中工作正常 - POST request blocked by CORS policy from local Angular application but works fine in Postman and Thunder Client 邮递员/其他客户正常工作,但通过角度应用程序进行飞行前验证错误 - Postman/Rest Client works but Pre flight Authentication error via angular application 获取 angular 8 发布 http 请求的问题,Postman 工作正常 - Problems with getting angular 8 to post http request, Postman works fine 角度2 http获取请求不通过节点服务器获取数据,而http发布正常 - angular 2 http get request not fetching data via node server while http post works fine 通过发布请求使用Angular和NodeJS发送图像 - Sending image via post request with Angular and NodeJS 尝试使用Angular访问API时遇到400错误的请求,但是使用PostMan时,它的工作效果很好 - Getting 400 bad request when trying to access an API using Angular, but it works perfectly fine when using PostMan c# asp .net core HTTP POST 请求适用于 Postman,但不适用于我的 Angular 客户端(404 错误) - c# asp .net core HTTP POST Request works with Postman but not with my angular client(404 error) 邮递员的请求有效但在角度上它没有 - the request in postman works but in angular it doesn't post 请求在 Postman 和 cURL 中有效,但在 Angular 中无效 - The post request works in Postman and in cURL but not in Angular 离职后的请求被cors阻止,而邮递员工作正常Ionic 4 - ionic post request blocked by cors while postman works fine Ionic 4
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM