Я пишу приложение сервера и хотел клиент, чтобы использовать данные в теле, чтобы 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.
Вы уверены, что принимающая сторона поддерживает его? [Запросы GET с телами не запрещены, но не ожидаются) (http://stackoverflow.com/questions/978061/http-get-with-request-body). – bzlm
Забудьте о документах, идите исследовать, что означает GET в http. – 7stud
Метод GET не поддерживает тело запроса –