2015-10-14 355 views
1

我有一个基本的silex应用程序,我尝试使用HTTPie进行测试。然而,在发帖时使用:如何使用HTTPie发送POST请求?

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

data,我从Request对象获得通过:

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

永远是空的。这里有什么问题?

回答

3

这是一个httpie使用问题,因为form标志是必需的,因为silex要求参数是表单编码的,但HTTPie的默认值是传递JSON对象。

$ 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" 
}