在尝试在Angular中发布数据时遇到未知错误。

huangapple go评论86阅读模式
英文:

Getting Unknown Error while trying to Post Data in angular

问题

我正在尝试从我的组件 TypeScript 页面发送一个 HTTP POST 请求来创建一条记录。但是我得到了一个 HttpErrorResponse 错误。

Typescript 文件:

onSubmit(form) {
  this.http.post('/api/providerapplication', JSON.stringify(form.value))
    .subscribe(result => {});
}

在尝试在Angular中发布数据时遇到未知错误。

英文:

I am trying to send an HTTP post request from my component typescript page to create a record. But I am getting an HttpErrorResponse error.
在尝试在Angular中发布数据时遇到未知错误。

TypescriptFile

    onSubmit(form) {
    this.http.post('/api/providerapplication', JSON.stringify(form.value))
      .subscribe(result => {});
}

答案1

得分: 1

你之所以收到这个消息,是因为你没有通过Postman发送OAuth令牌。确定OAuth令牌是如何发送的,并确保按照典型的登录请求方式发送。例如,我相信OAuth令牌通常是通过HTTP头部发送的。

英文:

You are getting this because you are not sending the oauth token via postman. Determine how the oauth token is sent and make sure it is sent in accordance with a typical logged in request. e.g. I believe oauth token is typically sent in the HTTP headers.

答案2

得分: 0

根据您提供的错误信息,我可以推断出您的后端应用程序在处理/api/providerapplication端点时出现了配置错误或错误地向用户报告问题。该HTTP端点返回一个错误消息,该消息是从内部客户端接收到的错误的字符串表示形式。客户端无法获取与某个外部服务通信的令牌。如果令牌是由用户(从浏览器)提交的,那么在这种情况下,您的后端应该以错误代码401作出响应,而不是500,因为缺少令牌。如果令牌是根据应用程序自身的应用程序配置中的凭据获取的,则需要更正配置。

值得一提的是,盲目复制所有内部错误信息并发送给用户并不是一个好的模式,因为这可能会泄露机密信息。

英文:

From the error message you have provided I can deduct that your backend application which is responsible for handling /api/providerapplication endpoint is somehow misconfigured or wrongly informs the user about the problem. This HTTP endpoint returns an error message which is a string representation of an error received from the internal client. The client cannot obtain the token to communicate with some external service. If the token is submitted by the user (from a browser) your backend should respond with error code 401 in this case instead of 500, since the token is missing. If the token is obtained based on credentials from the application configuration by the application itself you need to correct the configuration.

It is worth mentioning that it is not a good pattern to blindly copy all the information from internal errors and send it to the user, as this may reveal confidential information.

huangapple
  • 本文由 发表于 2021年9月14日 16:16:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/69174260.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定