【发布时间】:2019-03-15 09:30:47
【问题描述】:
在我的方法transmitProject(project: ProjectModel): Observable<boolean> 中有一个通过HttpClient 的发布请求,我想将数据发布到我的后端:
-- 在我的transmitProject-方法中
const params = {
projectId: project.projectId,
description: documentation.description,
// some other attributes ...
};
return this.http.post(this.conf.url, params).pipe(
map(response => {
console.log(response);
return true;
})
);
...直到这里一切正常。但是请求以 json 格式设置 post 数据。为了测试后端服务器,返回转储的 $_POST 变量 -> null。
请求负载: {projectId:“...”,描述:“...”,经度:10,纬度:10,... }
实际上应该是: projectId=...description=...longitude=10latitude=10...
-> 在 Postman 中一切正常。
【问题讨论】:
-
在您的请求中尝试
JSON.stringify(prams) -
以 JSON 传输数据是标准。你想让它们进行表单编码吗?
标签: angular ionic-framework rxjs httpclient