Angular 6 htttp POST-将参数设置为URL中的查询字符串
我有一个基于asp.net核心样板的应用程序。 我需要从我的Angular 6应用程序发送http POST参数 我的服务如下所示:Angular 6 htttp POST-将参数设置为URL中的查询字符串,angular,http-post,angular6,Angular,Http Post,Angular6,我有一个基于asp.net核心样板的应用程序。 我需要从我的Angular 6应用程序发送http POST参数 我的服务如下所示: public findProduct(productCode: string) { const url_ = 'api/product/findProduct'; const params = new URLSearchParams(); params.set('productCode', productCode); return this.http.post(
public findProduct(productCode: string) {
const url_ = 'api/product/findProduct';
const params = new URLSearchParams();
params.set('productCode', productCode);
return this.http.post(url_, params, httpHeaders)
.subscribe(
result => {
console.log(result);
},
error => {
console.log('There was an error: ')
}
);
我已经从@angular/http导入了URLSearchParams,但仍然存在同样的问题。我的帖子URL不好,因为API希望帖子URL如下:
和查询字符串参数,如:
产品代码:1111
但我的看起来是这样的:
和设置请求有效负载(始终为空):
我的httpHeaders是:
“内容类型”:“应用程序/json”,
“接受”:“文本/普通”
我的问题是如何在此服务中设置预期的API POST参数?您的问题或其中一个问题是您有ulr和url\u您从未指定您的服务器您在哪里指定本地主机?我在本文中没有提到。但是谢谢;)如果我错了,也请纠正我,但你似乎正在传递一个空的const参数。你确定这是一个帖子吗?听起来像是一个让我难以理解的问题,但我可能错了——这只是一个例子。我在调查情妇。是的,这是邮政。我知道它将被获取,但我不是后端开发人员:)
We have to pass params as 3rd parameter for post request
public findProduct(productCode: string) {
const url_ = 'api/product/findProduct';
const params = new URLSearchParams();
params.set('productCode', productCode);
return this.http.post(url_,,params, httpHeaders)
.subscribe(
result => {
console.log(result);
},
error => {
console.log('There was an error: ')
}
);
We have to pass params as 3rd parameter for post request
public findProduct(productCode: string) {
const url_ = 'api/product/findProduct';
const params = new URLSearchParams();
params.set('productCode', productCode);
return this.http.post(url_,,params, httpHeaders)
.subscribe(
result => {
console.log(result);
},
error => {
console.log('There was an error: ')
}
);