proxy.config 有什么问题:Angular 2

What is wrong with this proxy.config : Angular 2

我整理了以下proxy.config.json

{
  "/api/" {
    "target": "http://m.lowes.com/CatalogServices/product/nvalue/v1_0?nValue=4294857975&maxResults=6&showURL=1&rollUpVariants=1&showUrl=true&storeNumber=0595&priceFlag=rangeBalance&showMarketingBullets=1",
    "secure":false,
    "logLevel":"debug"
   }
}

这只是点击了可用于获取静态产品列表的后端。

我运行正在使用以下服务来获得这个JSON:

getProductData(){
    return this.http.get('/api/')
}

我有一个超级直接的订阅者来检查数据:

this.productServ.getProductData().subscribe(
  ( data ) => {console.log( data)},
  (err) => console.log(err)
 );
}

我的 npm 脚本是:

"start": "ng serve --proxy-config proxy.config.json"

但我收到以下错误:

ok: false
status: 400
statusText: "Bad Request"
type:2
url: "http://localhost:4200/api/
_body: "<HTML><HEAD>
<TITLE>Invalid URL</TITLE>
</HEAD><BODY>
<H1>Invalid URL</H1>
The requested URL
"http&#58;&#47;&#47;&#37;5bNo&#37;20Host&#37;5d&#47;CatalogServices&#47;product&#47;nvalue&#47;v1&#95;0&#63;", is invalid.<p>
Reference&#32;&#35;9&#46;1b7f1cb8&#46;1503983750&#46;cebb18
</BODY></HTML>

此外,如果我 运行 进入 PostMan,我会得到预期的 JSON。所以我知道 URL 很好。

严格按照其他代理帖子进行操作,但仍然一无所获。试着弄乱其中的一些,但没有走得太远。我有一种感觉,我正在做一些小事,但我只是没有看到它。建议?

编辑:

我差点忘了提到我在控制台中得到以下信息:

[HPM] GET /api/ -> http://m.lowes.com/CatalogServices/product/nvalue/v1_0?nValue=4294857975&maxResults=6&showURL=1&rollUpVariants=1&showUrl=true&storeNumber=0595&priceFlag=rangeBalance&showMarketingBul
lets=1

我是否认为这意味着我正在找到 url?如果是这样,为什么我会返回这个 400 错误?

找到大部分问题。这是解决 400 invalid url 问题的解决方案:

{
  "/api": {
    "target": "http://m.lowes.com/CatalogServices/product/nvalue",
    "pathRewrite": {
       "^/api/":""
    },
    "changeOrigin": true,
    "secure":false,
    "logLevel":"debug",
    "headers": {"host": "http://www.localhost:4200"}
  }
}

注意我删除了搜索参数。我在 http.

的选项中将它们添加为 urlSearchParameters

然而,这会产生一个新问题:

URL 要求没有尾部斜线。构建此服务的人没有编写任何内容来去除尾部的斜线,因此它将 1 的布尔值解析为 1/。这折腾和错误基本上说它不知道如何处理这个无效的选项。

有没有办法去掉这个尾部的斜杠?这似乎发生在 http 调用中,因为我传递的参数没有尾部斜杠。 Angular 似乎在末尾添加了自己的斜杠。这完全违背了我的意愿。

有谁知道当 http class 决定发送我的请求时如何从 url 参数中去除尾部斜杠?