拨测工具

by Miguel Bustamante

通过Miguel Bustamante

您可以卷曲多少? 快速简单地介绍有用的工具。 (How much can you cURL? A quick and easy intro to a useful tool.)

On a good day I can flex a 20 lb weight…twice. Probably. But that’s not the type of curling we’re talking about!

在美好的一天,我可以弯曲20磅的重量……两次。 大概。 但这不是我们在谈论的那种卷发!

Curl (or cURL), on the other hand, is a small but powerful tool for transferring files and data over URLs. On a smaller scale, it’s great for testing REST APIs. And, though most web developers might opt to use other tools such as Google’s Postman, cURL is done in the command line and can leave you feeling like a true computer hack with David Lightman-like skills (for you “War Games” fans).

另一方面,Curl(或cURL)是一个小型但功能强大的工具,用于通过URL传输文件和数据。 在较小的规模上,它非常适合测试REST API。 而且,尽管大多数Web开发人员可能选择使用其他工具,例如Google的Postman ,但cURL是在命令行中完成的,可以让您感觉像是具有David Lightman般技巧的真正的计算机黑客(对您来说是“战争游戏”的粉丝)。

CURL stands for “client” and “URL”, since it is a program run on the client side that makes HTTP requests to URL’s. Since it’s open source, you can download it here. Or if you have Gitbash already installed on your machine, it’s automatically included.

CURL代表“客户端”和“ URL”,因为它是在客户端运行的程序,该程序向URL发出HTTP请求。 由于它是开源的,您可以在此处下载。 或者,如果您的计算机上已经安装了Gitbash ,它将自动包含在内。

For the purposes of this quick intro, we’ll need a server that’ll allow us to make requests, and it seems JSON Placeholder fits our needs nicely. It is a fake REST API that, even though our requests won’t actually change the server’s database, will still give us the appropriate response. So go ahead and crack open that console and let’s get hacking!

出于本快速介绍的目的,我们需要一个允许我们进行请求的服务器,并且JSON Placeholder似乎很好地满足了我们的需求。 这是一个伪造的REST API,即使我们的请求实际上不会更改服务器的数据库,也仍会给我们适当的响应。 因此,继续破解该控制台,让我们开始吧!

得到 (Get)

To start, we’ll try a simple HTTP “get” request. Scroll down to the “Resources” section in JSON placeholder and let’s take a look at the types of objects we can make a request on.

首先,我们将尝试一个简单的HTTP“ get”请求。 向下滚动到JSON占位符中的“资源”部分,让我们看一下可以请求的对象类型。

Nice! We can call these objects by adding “/”, then the object we want in the URL. The number on the right of the row tells us how many items we’ll get back with this request. For starters, let’s request some users. Type the following line into the console:

真好! 我们可以通过添加“ /”,然后在URL中添加所需的对象来调用这些对象。 该行右边的数字告诉我们此请求将退还多少物品。 首先,让我们请求一些用户。 在控制台中输入以下行:

curl https://jsonplaceholder.typicode.com/users

You should see all ten users we were promised as JSON objects. But maybe I just want the fifth user. We’ll add “/5” after the URL to get the user with the I.D. of 5.

您应该看到我们被承诺为JSON对象的所有十个用户。 但是也许我只想要第五个用户。 我们将在URL后面添加“ / 5”,以获取ID为5的用户。

curl https://jsonplaceholder.typicode.com/users/5

We see the JSON object for the fifth user. Great, let’s try to post a user to the server.

我们看到了第五个用户的JSON对象。 很好,让我们尝试将用户发布到服务器。

发布 (Post)

“Post”- ing is the process of submitting data to the server and having it be saved in the database. To do this with cURL let’s look at its options. Type:

“发布”是将数据提交到服务器并将其保存在数据库中的过程。 为此,请看一下cURL。 类型:

curl --help

and you should get a bunch of cool options we can use in the terminal:

您应该可以在终端中使用很多不错的选择:

For our purposes, it looks like the “-d” or “- -data” option would work nicely. If we look back at the homepage of the placeholder, in the “Routes” section, it tells us we could make a post request to “https://jsonplaceholder.typicode.com/posts”. With this information, we’ll post our own object through the console:

就我们的目的而言,“-d”或“--data”选项似乎可以很好地工作。 如果我们回顾占位符的主页,在“路由”部分,它告诉我们可以向“ https://jsonplaceholder.typicode.com/posts ”发出发布请求。 有了这些信息,我们将通过控制台发布我们自己的对象:

curl -d "title=Greatest Post Ever Written&body=Body of the Greatest post ever written" https://jsonplaceholder.typicode.com/posts

Now you’ll see the post being “created” in the db, and it has an I.D. of 101.

现在,您将在数据库中看到该帖子正在“创建”,并且其ID为101。

更新资料 (Update)

Sometimes we need to change objects in the db. We can only change things already saved in the database, and since this is a fake REST API, our post wasn’t actually saved. So lets update a post that exists. How about the 56th one. Type:

有时我们需要更改数据库中的对象。 我们只能更改已经保存在数据库中的内容,并且由于这是一个伪造的REST API,因此我们的帖子实际上并未保存。 因此,让我们更新存在的帖子。 第56个怎么样? 类型:

curl https://jsonplaceholder.typicode.com/posts/56

And you’ll see:

您会看到:

It’s saved with some funky Lorem Ipsum text that we should probably change to something intelligible. We are going to need a few other options with our command here. First, we’ll need to tell cURL that it’s a “put” request. So as we look through our “- -help” option, it seems we could use “-X” to tell cURL we want to use a “PUT” command.

它与一些时髦的Lorem Ipsum文本一起保存,我们可能应该更改为可理解的文本。 在这里,我们的命令将需要其他一些选项。 首先,我们需要告诉cURL这是一个“放置”请求。 因此,当我们浏览“--help”选项时,似乎可以使用“ -X”告诉cURL我们要使用“ PUT”命令。

Then we still want to use the “-d” option for the new data we intend to use. Let’s piece it all together. Type:

然后,我们仍然要对要使用的新数据使用“ -d”选项。 让我们拼凑起来。 类型:

curl -X PUT -d "title=This is a new title" https://jsonplaceholder.typicode.com/posts/56

And just like that, we have changed the title of the post with the I.D. of 56 to what we wanted.

就像这样,我们将ID为56的帖子标题更改为所需的标题。

删除 (DELETE)

And now we come to the delete. Ahh, the delete. If all else fails, destroy it all! We are going to see some of the same code as we saw in the PUT command, but all we need is to give cURL a DELETE request and the URL to the post we are to delete.

现在我们来删除。 啊,删除。 如果其他所有方法均失败,则将其全部销毁! 我们将看到与在PUT命令中看到的相同的代码,但是我们所需要的只是给cURL一个DELETE请求和要删除的帖子的URL。

curl -X DELETE https://jsonplaceholder.typicode.com/posts/56

Notice that you get nothing back in return but a newline. Maybe on some consoles you’ll see and empty hash(“{}”). This indicates that there is nothing to return because it was deleted.

注意,除了换行符之外,您什么也没有得到回报。 也许在某些控制台上您会看到并清空hash(“ {}”)。 这表明没有东西要返回,因为它已被删除。

结语 (Wrapping up)

We only touched on some cURL commands at a very superficial level. It is a neat tool that can be helpful when working on fully functioning API integration in your app. I would suggest looking at the manual for further reading and playing around with the different options to see what may fit your needs.

我们仅在非常肤浅的层次上触及了一些cURL命令。 这是一个简洁的工具,当您在应用程序中进行功能全面的API集成时可能会有所帮助。 我建议您查看手册,以进一步阅读并尝试使用不同的选项,以了解可能适合您的需求。

翻译自: https://www.freecodecamp.org/news/how-much-can-you-curl-3c88e2fed3f6/

拨测工具

拨测工具_您可以拨多少钱? 快速简单地介绍有用的工具。相关推荐

  1. 网络拨测厂商提供的网页拨测系统有哪些拨测率指标?

    在之前的文章中点量软件,为大家介绍了视频网站性能拨测能提供的指标有哪些.用户上网出除了看视频再就是刷网页,和视频网络传输指标类似,网页浏览也有一系列的指标来显示当时的网络情况.点量的网页浏览检测的是真 ...

  2. sql自动生成工具_可自动生成代码,5款基于AI的开发工具

    如今,对机器学习潜力感兴趣的程序员都在讨论,如何使用人工智能和基于人工智能的软件开发工具构建应用程序.例如PyTorch和TensorFlow之类的解决方案. 除此之外,机器学习技术正以另一种有趣的方 ...

  3. java 开发人员工具_每个Java开发人员都应该知道的10个基本工具

    java 开发人员工具 大家好,我们已经到了2019年的第二个月,我相信你们所有人都已经制定了关于2019年学习以及如何实现这些目标的目标. 我一直在撰写一系列文章,为您提供一些知识,使您可以学习和改 ...

  4. python怎么开发工具_为程序员和新手准备的8大Python开发工具

    Python 是一种开源编程语言,用于 Web 编程.数据科学.人工智能和许多科学应用.学习 Python 使程序员能够专注于解决问题,而不是专注于语法,其丰富的库赋予它完成伟大任务所需的力量. 1) ...

  5. 倒计时小工具_想要工作效率更高?这几款计时工具你一定不能错过!

    Mac计时器是Mac平台上的任务管理计时工具合集.Mac计时器是Mac上的指定操作的倒计时工具,能够帮助我们在Mac电脑上快速建立倒计时任务,可以帮助我们提高生产效率和工作质量.使用最流行的时间管理技 ...

  6. python亚马逊运营工具_使用亚马逊云服务必备的八款SaaS工具

    原标题:使用亚马逊云服务必备的八款SaaS工具 这些年做项目的过程中收集了相当多的工具和服务来简化开发者.系统管理员以及DevOps的日常工作. 基本上所有的PHP.Python或者Ruby开发者都与 ...

  7. 关键词分词工具_为解决万千竞价员分词痛苦的——厚昌分词工具2.0版 即将正式上线...

    ​​01 竞价推广是企业在进行营销推广时一定不会放过的一种推广方式. 于企业来说,竞价推广是可以以较低的成本,较短的时间,带来更多的精准目标人群,获取较大效益的一种推广方式.于竞价员而言,搭建一个优质 ...

  8. 华为开源构建工具_为什么我构建了用于大数据测试和质量控制的开源工具

    华为开源构建工具 I've developed an open-source data testing and a quality tool called data-flare. It aims to ...

  9. 一键移植工具_【产品推广】让UI设计畅通无阻 — 信息系统人机界面增强工具(HFE Designer)...

    2020年7月1日,中国船舶工业综合技术经济研究院船舶人因工程研究中心(深远海人因工程实验室)正式成立.本中心专业从事船舶人因工程相关技术研究,经过10年技术积累形成了关键岗位选拔与训练.深远海装备人 ...

最新文章

  1. 分布式事务的实现原理
  2. MATLAB符号计算
  3. Android --- 屏幕方向screenOrientation属性详解
  4. DataGrid 中的特殊应用
  5. Python Django 设置/更改响应头信息
  6. android系统sharedUserId: SYSTEM_UID+PHONE_UID+BLUETOOH_UID+LOG_UID+NFC_UID
  7. 求生之路 服务器优化参数,《求生之路2》服务器及网络参数优化指南
  8. 伸缩轨道_深度解析——伸缩喷漆房为什么这么受欢迎!
  9. 实例25:python
  10. 软件测试用例项目写作,通用测试用例写作方法
  11. 采用contentprivider扫描手机SD卡的图片资源
  12. Windows微秒级定时方法
  13. NGUI字体贴图压缩以及相关Shader解读
  14. maven项目多模块部署的时候构建顺序
  15. 【Proteus】如何在Proteus中将网络标号批量标号
  16. word更新域后图片错误_你还不知道Word中F1~F12键作用?
  17. html克隆元素增加id,h.js - 元素克隆与追加
  18. 分组取出值最大的数据
  19. 兴业证券:主动偏股型基金评价体系
  20. html 图标制作,icon小图标制作

热门文章

  1. Java封装(速读版)
  2. c++窗口管理系统是什么_优秀的食堂管理系统让你对校园生活更充满希望
  3. 随机位置显示图片不重叠前端实现详细讲解附效果图,代码可直接使用
  4. 《深入理解Android:Wi-Fi,NFC和GPS》章节连载[节选]--第六章 深入理解wi-Fi Simple Configuration...
  5. 北京智能计算产业研究院落户顺义,中科睿芯联手计算所、顺义区打造“产业园2.0”...
  6. MySQL , MHA , Haproxy 配置
  7. 一种新的攻击方式:使用Outlook 表单进行横向渗透和常驻
  8. ORM武器:NHibernate(三)五个步骤+简单对象CRUD+HQL
  9. js判断鼠标位置是否在某个div中
  10. 便捷,轻巧的Groovy数据库操作