angular - Angular 6 将数据发布到休息 API 但返回错误 500
问题描述
我需要将数据发布到其余 API,但它返回错误 500。当我在 Postman 中测试 API 时,API 正在工作。
身份验证.service.ts
register(email: string, fullName: string,contactNo: string) {
var data = {
'email' : email,
'fullName' : fullName,
'contactNo': contactNo
};
return this.http.post<any>(`http://localhost:80/user`, {data})
.pipe(map(user => {
JSON.stringify(user);
return user;
}));
}
解决方案
您正在发布一个具有名为 data 的属性的对象,该属性设置为您的对象数据。从数据周围删除花括号。你的身体看起来像
{
data: {
email: email,
fullName: fullName,
contactNo: contactNo
}
}
尝试
register(email: string, fullName: string,contactNo: string) {
var data = {
'email' : email,
'fullName' : fullName,
'contactNo': contactNo
};
return this.http.post<any>(`http://localhost:80/user`, data)
.pipe(map(user => {
JSON.stringify(user);
return user;
}));
}
推荐阅读
- nginx - 如何清除 nginx 中的 keys_zone 内存
- java - 将 Object 的对象变成不同类型的对象?
- ios - 如何通过单击添加来添加一个单元格,该单元格将采用 TextField 值并在该表格视图中创建一个包含该文本的单元格,如下图 Swift/Obj-C 中的图像?
- assembly - 尝试在 x86 汇编中进行乘法运算,使用 rax、rdi、rsi 和 rcx 寄存器
- flutter - Flutter 应用程序无法调用 API。未处理的异常:键入“列表”
' 不是类型 'Map 的子类型 ' - go - ANTLR4 内存使用
- php - Laravel route() 为 localhost 返回错误的 url
- python-3.x - Django forms.ModelForm slugfield db_index=True
- tensorflow - keras 和 tf.keras 的区别
- ios - iOS USB 文件传输