How to send a POST request using HTTPie?

2019-02-28 02:34发布

I have a basic silex application, and I try to test it using HTTPie. Yet when posting using:

http POST http://localhost:1337 data="hello world"

The data, that I get from the Request object via:

$data = $request->request->get('data');

will always be empty. What is the problem here?

1条回答
Emotional °昔
2楼-- · 2019-02-28 03:00

It was an httpie usage problem as the form flag was necessary, as silex requires the parameters to be form-encoded, yet the default of HTTPie is to pass a JSON object.

$ http --form POST http://localhost:1337 data="hello world"

HTTP/1.1 200 OK
Cache-Control: no-cache
Connection: close
Content-Type: application/json
Date: Wed, 14 Oct 2015 15:04:09 GMT
Host: localhost:1337
X-Powered-By: PHP/5.5.9-1ubuntu4.13

{
    "message": "hello world"
}
查看更多
登录 后发表回答