使用cURL查询REST API [英] Querying REST API using cURL

查看:294
本文介绍了使用cURL查询REST API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我是一个新手,既有 REST cURL 。这是我想要做的:

To begin with I am a novice, both with REST and cURL. This is what I want to do:

我想使用命令行(一些bash脚本)查询Twitter Rest API,因此,我想使用 cURL 来做。

I want to query the Twitter Rest API using commandline (some bash script) and hence, I want to use cURL to do that.

我一直在试图搜索一些教程(没有运气),解释了如何使用 REST code> cURL 以及如何形成标头,get / post以及如何接收 REST 响应和响应状态,我可以根据响应状态写我的逻辑。

I have been trying to search for some tutorial (with no luck) that explains how to use REST with cURL and how to form the headers, get/post and then how to receive the REST response and the response status, so that I can write my logic based on the response status.

我非常感谢您能给我一些如何使用curl调用twitter REST API的示例,以及如何访问 REST 响应状态。

I would greatly appreciate if you can give me a few examples on how to call the twitter REST API using curl and also how to access the REST response status.

我尝试使用以下命令呼叫Twitter:

I tried calling twitter using this:

curl "http://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&screen_name=$user_name&count=150"

得到一个json,我可以在我的程序中使用。但我不知道如何访问其余的响应状态代码(以使我的实现更可靠)。另外,我不知道在调用它时我应该为cURL提供什么其他标志。

And got a json which I was able to use in my program. But I am not sure how to access the rest response status codes (in order to make my implementation more reliable). Also, I am not sure about what other flags should I provide to the cURL while calling it.

PS:只要添加,如果你认为有一些其他MUCH更好的替代从REST API检索数据使用cURL,那么也请让我知道。虽然我的应用程序不是基于Web和更多的数据处理导向,这就是为什么我选择命令行和bash。

PS: Just to add, if you think there is some other MUCH better alternative to retrieving data from REST API other that using cURL, then also please let me know. Though my application is not web based and is more data crunching oriented and that's why I chose commandline and bash.

推荐答案

curl -i将打印标题信息:

curl -i will print out the header information:

HTTP/1.1 200 OK
Date: Sat, 29 Dec 2012 07:34:00 GMT

这篇关于使用cURL查询REST API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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