[英]How to send angularjs $http GET request with body
I know a GET request shouldn't have a body, but unfortunately when writing the server I didn't know that, and I am not allowed to change it.我知道 GET 请求不应该有正文,但不幸的是,在编写服务器时我不知道这一点,而且我不允许更改它。 The server(Node.js) expects the get request to contain a body with a parameter.
服务器(Node.js)期望获取请求包含一个带有参数的主体。 When searching for the issue I have seen a few answers mention that it is possible but none said how.
在搜索问题时,我看到一些答案提到这是可能的,但没有人说如何。 I have tried to send it this way with no success:
我试图以这种方式发送它但没有成功:
$http.get('http://localhost:3000/foo/bar',{
data: {'foo':bar},
headers: {'Content-Type': 'application/json;charset=utf-8'}
})
Thanks!谢谢!
From the Docs: 从文档中:
The XMLHttpRequest method
send()
, sends the request to the server.XMLHttpRequest方法
send()
,将请求发送到服务器。If the request method is GET or HEAD, the body parameter is ignored and the request body is set to
null
.如果请求方法是GET或HEAD,则将忽略body参数,并将请求主体设置为
null
。
Since the $http.get
method wraps the XHR.send() method, it can't send a body with its request. 由于
$http.get
方法包装了XHR.send()方法,因此无法发送带有其请求的正文。
For more information, see 有关更多信息,请参见
你可以通过身体参数来获得这样的要求
$http.get('http://localhost:3000/foo/bar',{params: {'foo':bar}} })
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.