如何使用HTTPie发送POST请求? [英] How to send a POST request using HTTPie?

查看:1860
本文介绍了如何使用HTTPie发送POST请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基本的silex应用程序,我尝试使用 HTTPie 进行测试。然而,使用以下方式发布时:

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"

数据,我通过以下方式从Request对象获得:

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

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

将始终为空。这里有什么问题?

will always be empty. What is the problem here?

推荐答案

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

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

这篇关于如何使用HTTPie发送POST请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆