我如何使用 post 方法对 Angular 中的 api 执行 http-request 9
How can i do an http-request with a post method to an api in Angular 9
这是我第一次尝试这样做,我不知道如何开始,如果有人能指导我,那将是非常有帮助的。我正在尝试登录,如果我想让它正常工作,我必须使用 post 方法向 API 发出 http 请求,然后 return 我需要的信息,但是当我尝试使用 URL 说错误 404 时,我尝试使用 Postman
并说出我将在下面给出的其他错误。 我不是说必须有人为我做,只是需要有人告诉我如何开始
- 这是
API
https://devapi.shocklogic.com/v1.0/:key/Users/login/
- 为了向这个端点提出请愿,我必须在 header
Token
Token-App' 中发送这个令牌:'7875d82ca05f8ba818011eb04a890c20cb44c52e'
- 我还需要发送三个参数
Key
、Identifier of the person
和 Password
Postman
说的错误
{
"type": "error",
"message": "please make sure your meet the following field requirements",
"check": 0,
"passed": false,
"requirements": [
[
"Identifier",
{
"is_required": true,
"requires_value": true,
"min_length": 1,
"max_length": 150
}
],
[
"Password",
{
"is_required": true,
"requires_value": true,
"min_length": 1,
"max_length": 60
}
]
]
}
这是执行 post 请求
的示例代码
let headers = new Headers({'Content-Type': 'application/json'});
headers.append('Authorization','Bearer <your auth here>')
let options = new RequestOptions({headers: headers});
const body = { username, password }; // will depend on how your api will accept
return this.http.post(APIname,body,options)
.map(this.extractData)
.catch(this.handleError);
这是我第一次尝试这样做,我不知道如何开始,如果有人能指导我,那将是非常有帮助的。我正在尝试登录,如果我想让它正常工作,我必须使用 post 方法向 API 发出 http 请求,然后 return 我需要的信息,但是当我尝试使用 URL 说错误 404 时,我尝试使用 Postman
并说出我将在下面给出的其他错误。 我不是说必须有人为我做,只是需要有人告诉我如何开始
- 这是
API
https://devapi.shocklogic.com/v1.0/:key/Users/login/ - 为了向这个端点提出请愿,我必须在 header
Token
Token-App' 中发送这个令牌:'7875d82ca05f8ba818011eb04a890c20cb44c52e' - 我还需要发送三个参数
Key
、Identifier of the person
和Password
Postman
说的错误
{
"type": "error",
"message": "please make sure your meet the following field requirements",
"check": 0,
"passed": false,
"requirements": [
[
"Identifier",
{
"is_required": true,
"requires_value": true,
"min_length": 1,
"max_length": 150
}
],
[
"Password",
{
"is_required": true,
"requires_value": true,
"min_length": 1,
"max_length": 60
}
]
]
}
这是执行 post 请求
的示例代码let headers = new Headers({'Content-Type': 'application/json'});
headers.append('Authorization','Bearer <your auth here>')
let options = new RequestOptions({headers: headers});
const body = { username, password }; // will depend on how your api will accept
return this.http.post(APIname,body,options)
.map(this.extractData)
.catch(this.handleError);