【发布时间】:2017-12-14 09:21:14
【问题描述】:
我想在我的 GET 请求中使用正文。我没有找到任何使用 Angular 2/4 的方法。
我在RequestOptionsArgs 类中找到了body 属性,但它没有在http 请求中发送。
httpie.org 可以这样发送:
http --verbose GET 'http://localhost/api/test' 'Content-Type: application/json' 'foo=bar'
这是发送这个原始请求:
GET /api/test HTTP/1.1
Accept: application/json, */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Length: 14
Content-Type: application/json
Host: localhost
User-Agent: HTTPie/0.9.9
enter code here
{
"foo": "bar"
}
this.http.get("/api/test", {body: JSON.stringify{foo: "bar"}})
【问题讨论】:
-
你不能在 angular2/4 中这样做
-
需要结论
-
使用 Angular 2/4 你不能发送正文。一般来说,您可以使用 GET 发送请求正文,但它应该没有任何意义。如果您通过在服务器上解析它并根据其内容更改响应来赋予它意义,那么您将忽略 HTTP/1.1 规范第 4.3 节中的此建议:
-
泰!很好的回应! :)