$ http.get()和JSON数据 [英] $http.get() with JSON data
本文介绍了$ http.get()和JSON数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在写一个应用程序服务器,并希望客户端使用的数据在身体pararmeterize我GET方法,如:
I'm writing a server app and wanted the client to use data in body to pararmeterize my GET method, like this:
# http -v GET http://localhost:3000/url text=123 foo=bar
GET /url HTTP/1.1
Accept: application/json
Accept-Encoding: gzip, deflate, compress
Content-Length: 29
Content-Type: application/json; charset=utf-8
Host: localhost:3000
User-Agent: HTTPie/0.4.0
{
"foo": "bar",
"text": "123"
}
在AngularJS我尝试:
In AngularJS I tried:
var params = {
"foo": "bar",
"text": "123"
}
// no body
$http({
method: 'GET',
url: '/url',
data: params })
// ugly url
// also has its limitation: http://stackoverflow.com/questions/978061/http-get-with-request-body
$http({
method: 'GET',
url: '/url',
params: params })
// params in body, but I wanted GET
$http({
method: 'POST',
url: '/url',
data: params })
这设计还是错误是?
我不能看到从文档为什么。
推荐答案
我想借此作为答案:
这不是禁止的,但你不应该使用它作为服务器可能(和应该)忽略 GET
请求的主体。
it's not prohibited, but you shouldn't use it as the server may (and SHOULD) ignore the body of GET
request.
参考: HTTP GET请求与身
这篇关于$ http.get()和JSON数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文