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

news/2024/7/7 18:49:44

拨测工具

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/

拨测工具


http://lihuaxi.xjx100.cn/news/239468.html

相关文章

oracle重建实例_记一次误删Oracle控制文件并恢复过程

概述当你在数据库运行时误删除了控制文件怎么办?很不幸有一次我就有这个情况,虽然是测试环境,这里因为我有事先把控制文件分别备份,所以恢复还是比较简单的。下面简单记录下怎么恢复。问题控制文件版本不一致一般是因为在实例运行时删除了控制…

ElasticSearch + xpack 使用

ElasticSearch 是一个高可用开源全文检索和分析组件。提供存储服务,搜索服务,大数据准实时分析等。一般用于提供一些提供复杂搜索的应。我们为什么要选择 ElasticSearch ?因为它是一个准实时的搜索工具,在一般情况下延时少于一秒&…

华为hybrid-vlan

华为hybrid-vlan、三层交换、DHCP拓扑&#xff1a;需求&#xff1a;1.路由器终结vlan2.交换机间以hybrid方式透传vlan3.PC以DHCP获取IP思路&#xff1a;1.PC的网关在路由器上2.配置hybrid-vlan3.配置DHCP步骤&#xff1a;路由器AR1&#xff1a;<Huawei>sy[Huawei]vlan 10…

mysql如何用cmd启动mysql_通过cmd启动mysql

1)cmd 启动mysql&#xff1a;本地&#xff1a;服务器&#xff1a;2)通过rpm的方式linux本地安装mysql注意&#xff1a;要安装的是两个东东&#xff0c;一个是服务器&#xff0c;一个客户端&#xff0c;肯定要先装服务器再装客户端的嘛安装服务器&#xff1a;发现了包冲突&#…

如何在Tensorflow.js中处理MNIST图像数据

by Kevin Scott凯文斯科特(Kevin Scott) 如何在Tensorflow.js中处理MNIST图像数据 (How to deal with MNIST image data in Tensorflow.js) There’s the joke that 80 percent of data science is cleaning the data and 20 percent is complaining about cleaning the data …

Xcode 创建.a和framework静态库(转)

最近因为项目中的聊天SDK&#xff0c;需要封装成静态库&#xff0c;所以实践了一下创建静态库的步骤&#xff0c;做下记录。 库介绍 库从本质上来说是一种可执行代码的二进制格式&#xff0c;可以被载入内存中执行。库分静态库和动态库两种。iOS中的静态库有 .a 和 .framework两…

mysql减少锁等待_降低锁竞争 减少MySQL用户等待时间

【IT168 技术】通过锁机制&#xff0c;可以实现多线程同时对某个表进行操作。如下图所示&#xff0c;在某个时刻&#xff0c;用户甲、用户乙、用户丙可能会同时或者先后(前面一个作业还没有完成)对数据表A进行查询或者更新的操作。当某个线程涉及到更新操作时&#xff0c;就需要…

firebase 推送_如何使用Firebase向Web应用程序添加推送通知?

firebase 推送by Leonardo Cardoso由莱昂纳多卡多佐(Leonardo Cardoso) 如何使用Firebase向Web应用程序添加推送通知&#xff1f; (How to add push notifications to a web app with Firebase ??) As web applications evolve, it is increasingly common to come across f…