小编Woj*_*ech的帖子

Angular 6 htttp POST - 将参数设置为 URL 中的查询字符串

我有一个基于 asp .net core 样板的应用程序。我需要从我的 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(url_, params, httpHeaders)
  .subscribe(
    result => {
      console.log(result);
    },
    error => {
      console.log('There was an error: ')
    }
  );
Run Code Online (Sandbox Code Playgroud)

我已经从 @angular/http 导入了 URLSearchParams,但仍然遇到同样的问题。我的 POST URL 很糟糕,因为 API 期望 POST URL 如下所示: http://localhost:21021/api/product/findProduct?productCode=1111并查询字符串参数,如: productCode: 1111

但我的看起来像这样: http://localhost:21021/api/product/findProduct 并设置请求负载(始终为空):

**{rawParams: "", queryEncoder: {}, paramsMap: {}}
paramsMap: {}
queryEncoder: {}
rawParams: ""**
Run Code Online (Sandbox Code Playgroud)

我的 httpHeaders …

http-post angular angular6

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

angular ×1

angular6 ×1

http-post ×1