问题描述
我正在为Web应用程序构建Web服务,我想要一个简单的工具来测试这个,因为我正在开发。我尝试过一些firefox插件(Poster,'REST Client'),虽然这些工作正常,我无法与他们上传文件。
I am building a web service for a web application, and I would like a simple tool to test this as I am developing. I have tried some firefox plug-ins (Poster, 'REST Client'), and even though these work fine I have been unable to upload files with them.
我宁愿有一个命令行工具,我可以使用它来轻松地为这个Web服务编写一组集成测试,我可以发送给这个Web服务的消费者为例。
Also, I would rather have a command-line tool that I can use to easily write a set of integration tests for this web service and that I can send to consumers of this web service as an example.
我知道 curl
可以工作,但是想要几个例子,特别是围绕认证(使用HTTP基本)
I know that curl
can work for this but would like a few examples, especially around authentication (using HTTP Basic) and file uploads.
推荐答案
除了现有的答案,通常需要格式化REST输出(通常JSON和XML缺少缩进)。请尝试以下操作:
In addition to existing answers it is often desired to format the REST output (typically JSON and XML lacks indentation). Try this:
$ curl https://api.twitter.com/1/help/configuration.xml | xmllint --format -
$ curl https://api.twitter.com/1/help/configuration.json | python -mjson.tool
在Ubuntu 11.0.4 / 11.10上测试。
Tested on Ubuntu 11.0.4/11.10.
另一个问题是所需的内容类型。 Twitter使用 .xml
/ .json
扩展,但更惯用的REST需要 code> header:
Another issue is the desired content type. Twitter uses
.xml
/.json
extension, but more idiomatic REST would require Accept
header:
$ curl -H "Accept: application/json"
这篇关于如何使用命令行curl测试Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!