2013-04-25 77 views
11

我正在写一个服务器应用程序,并希望客户端使用的数据在体内pararmeterize我GET方法,像这样:

# 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我想:

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 }) 

这是设计还是错误?我不明白为什么从documentation

+3

确定接收端支持它? [与身体的GET请求是不被禁止的,但不预期](http://stackoverflow.com/questions/978061/http-get-with-request-body)。 – bzlm 2013-04-25 08:54:13

+2

忘记文档,去研究GET在http中的含义。 – 7stud 2013-04-25 08:54:25

+0

GET方法不支持请求主体 – 2013-04-25 08:55:56

回答