angular - 我如何使用 Angular 9 中的 api 的 post 方法执行 http 请求
问题描述
这是我第一次尝试这样做,我不知道如何开始,如果有人可以指导我,那将非常有帮助。我正在尝试登录,如果我想让它工作,我必须使用 API 的 post 方法发出 http 请求,并将返回我需要的信息,但是当我尝试说带有 URL 的错误 404 时,我尝试了并Postman
说我将在下面给出的其他错误。我不是说必须有人为我做,只是需要有人告诉我如何开始
- 这是
API
https://devapi.shocklogic.com/v1.0/:key/Users/login/ - 要向此端点提出请愿书,我必须在标头
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
}
]
]
}
解决方案
这是一个执行发布请求的示例代码
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);
推荐阅读
- php - 使用php从目录上传图像
- excel - 如何在 Excel 中制作一个自动值计算器?
- wordpress - Wordpress 中的粗体字幕
- c# - Web 浏览器控件 C# 的问题
- java - if Scanner Boolean statement with 2 nextInt() 和 hasNextInt() 问题
- wordpress - 需要将 plugin 和 functions.php 从 $_SESSION 更改为 Cookie
- java - 在 Intellij IDEA 中生成 Pitest 报告失败
- java - getContext() 在 Fragment 中返回 null。视图似乎未附加
- html - 用手风琴画线
- vuejs2 - UIkit 和 NuxtJS offcanvas 在移动到页面后不会关闭