英文:
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 => {});
}
英文:
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.
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论