当前位置: 首页 > 编程日记 > 正文

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

拨测工具

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/

拨测工具

相关文章:

leetcode第一刷_Recover Binary Search Tree

这是一道好题,思路尽管有,可是提交之后总是有数据过不了,又依照数据改改改。最后代码都没法看了。收到的教训是假设必须为自己的代码加上非常多非常多特殊的限定。来过一些特殊的数据的话。说明代码本身有非常大的漏洞。 这道题,我…

Java中的文件路径

通常情况下,在Java项目中,我们使用的路径都是在拿到类加载路径后,根据相对位置,使用 FilePathTest.class.getResourceAsStream(relativePath);拿到文件。今天小生不使用classPath,而是直接去使用相对路径来…

js上传文件,上传表单demo 包含后端php

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 正文&#xff1a; <!DOCTYPE html> <html lang"zh"><head><meta charset"UTF-8"><title>Title</title><script src"https://ajax.as…

如何在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 …

常用图像额文件格式及类型

1、显示一幅二值图像&#xff1a; >> bw zeros(90,90); >> bw(2:2:88,2:2:88) 1; >> imshow(bw); >> 2、利用image函数显示一幅索引图像&#xff1a; >> [X,MAP] imread(E:\STUDY_software\Matlab2016\images\11.jpg); >> image(X); &…

微信小程序实现滑动翻页效果源码附效果图

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 正文&#xff1a; 微信小程序实现滑动翻页效果 效果图&#xff1a; 源码&#xff1a; <view class"mainFrame"><swiper class"container" indicator-dots"{{indic…

Ubuntu 系统 文件操作命令

文件和目录的操作 用户主目录下有一个 Desktop (对应,桌面)mkdir dir1 建立一个目录cd 不添加参数,默认回到主目录(用户目录)touch a.txt 建立一个文件mv a.txt Desktop/ 移动到Desktop/中 mkdir dir1cp -r dir1/ dir2 不加-r或者&#xff0d;R的时候&#xff0c;只拷贝文件&am…

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…

lucene构建同义词分词器

lucene4.0版本号以后 已经用TokenStreamComponents 代替了TokenStream流。里面包含了filter和tokenizer 在较复杂的lucene搜索业务场景下&#xff0c;直接网上下载一个作为项目的分词器&#xff0c;是不够的。那么怎么去评定一个中文分词器的好与差&#xff1a;一般来讲。有两个…

正则匹配出字符串中两串固定字符区间的所有字符

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 正文&#xff1a; 效果&#xff1a;匹配两个字符串区间的字符串 代码&#xff1a; var dd[];var str is_img"https://www.baidu.com/"is_img11is_img"https://www.baidu.com/"is…

识别手写字体app_我如何构建手写识别器并将其运送到App Store

识别手写字体app从构建卷积神经网络到将OCR部署到iOS (From constructing a Convolutional Neural Network to deploying an OCR to iOS) 项目动机✍️?? (The Motivation for the Project ✍️ ??) While I was learning how to create deep learning models for the MNIS…

20155307 2016-2017-2 《Java程序设计》第10周学习总结

20155307 2016-2017-2 《Java程序设计》第10周学习总结 教材学习内容总结 网络编程&#xff1a;就是在两个或两个以上的设备(例如计算机)之间传输数据。程序员所作的事情就是把数据发送到指定的位置&#xff0c;或者接收到指定的数据。在发送和接收数据时&#xff0c;大部分的程…

WinForm 实现验证码

private void CheckIdentifyingCode() { Random r new Random(); string str ""; for (int i 0; i < 5; i) { int a r.Next(0, 10); str a;//将数字连接到一块 } Bitmap bm new Bitmap(150, 90);//创建位图对象 Graphics g Graphics.FromImage(bm);//在bm中…

微信小程序打开预览下载的文件

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 使用 wx.openDocument(obj) 方法预览 wx.downloadFile({url: http://example.com/somefile.pdf,success: function (res) {var filePath res.tempFilePathwx.openDocument({filePath: filePath,success…

aws lambda_为什么我会自动删除所有旧的推文以及我用来执行此操作的AWS Lambda函数...

aws lambdaFrom now on, my tweets are ephemeral. Here’s why I’m deleting all my old tweets, and the AWS Lambda function I’m using to do all this for free.从现在开始&#xff0c;我的推文只是短暂的。 这就是为什么我删除所有旧的推文&#xff0c;以及免费使用所有…

Topcoder SRM 657DIV2

前言: 像我这样一直在DIV2的弱菜。。不知道说什么了。 A:一定判断有8个‘R’&#xff0c;每行 每列只有一个 B题&#xff1a;大概是 int E,int EM,int M,int MH,int H 然后EM可以给值到E&#xff0c;M&#xff0c;MH可以给值到H&#xff0c;M&#xff1b; 我的做法二分&#x…

微信小程序换行,空格的写法

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 正文&#xff1a; 1.文本超出部分自动换行&#xff0c;前后对比 实现代码&#xff1a; flex-wrap: warp;white-space: pre-wrap; 2.text 手动添加换行的写法 { text: 12测试换\n行符&#xff0c;测试\…

我是如何在尼日利亚的沃里创立Google Developers Group GDG分会的,并达到了100位成员...

It only takes a spark to get a fire going, and soon all those around can warm up in its glowing. — Kurt Kaiser, Pass It On只需要一点火花就能使火熄灭&#xff0c;周围的所有人很快就会在炽热的火焰中升温。 — Kurt Kaiser&#xff0c;传递下去 I am convinced beyo…

ES6 你可能不知道的事 – 基础篇

ES6 你可能不知道的事 – 基础篇 转载作者&#xff1a;淘宝前端团队&#xff08;FED&#xff09;- 化辰 链接&#xff1a;taobaofed.org/blog/2016/07/22/es6-basics/ 序 ES6&#xff0c;或许应该叫 ES2015&#xff08;2015 年 6 月正式发布&#xff09;&#xff0c;对于大多数…

Android线程之主线程向子线程发送消息

和大家一起探讨Android线程已经有些日子了&#xff0c;谈的最多的就是如何把子线程中的数据发送给主线程进行处理&#xff0c;进行UI界面的更新&#xff0c;为什么要这样&#xff0c;请查阅之前的随笔。本篇我们就来讨论一下关于主线程向子线程如何发送数据&#xff0c;这个用的…

HTML上传excel文件,php解析逐条打印输出

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 正文&#xff1a; phpExcel文件下载 ←跳转地址 demo <!DOCTYPE html> <html lang"zh"><head><meta charset"UTF-8"><title>Title</title>…

javascript编写_如何通过编写自己的Web开发框架来提高JavaScript技能

javascript编写Have you ever asked yourself how a framework works?您是否曾经问过自己框架是如何工作的&#xff1f; When I discovered AngularJS after learning jQuery many years ago, AngularJS seemed like dark magic to me.多年前学习jQuery后&#xff0c;当我发现…

2016ACM/ICPC亚洲区大连站现场赛题解报告(转)

http://blog.csdn.net/queuelovestack/article/details/53055418 下午重现了一下大连赛区的比赛,感觉有点神奇,重现时居然改了现场赛的数据范围,原本过的人数比较多的题结果重现过的变少了,而原本现场赛全场过的人最少的题重现做出的人反而多了一堆,不过还是不影响最水的6题,然…

微信小程序插件新增能力

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 正文&#xff1a; “ 小程序插件能力升级&#xff1a;开放插件登录能力&#xff0c;帮助插件开发者更好地管理用户&#xff1b;支持在插件内使用微信支付能力&#xff0c;便于用户在插件内完成预订、购…

ubutun:从共享文件夹拷贝文件尽量使用cp命令而不是CTRL+C/V

为了方便&#xff0c;VBOX安装的Ubuntu&#xff0c;并在硬盘上创建了一个与Windows的共享文件夹sharefolder方便在两个系统之间传文件 但是经常发现的问题就是从sharefolder中拷贝文件到ubuntu中会出现很多毛病&#xff0c;比如说经常按了CTRLC之后没有拷贝最新的文件&#xff…

影像锐化工具_如何以及为什么要进行工具改造:花在锐化斧头上的时间永远不会浪费...

影像锐化工具by Harshdeep S Jawanda通过Harshdeep S Jawanda 如何以及为什么要进行工具改造&#xff1a;花在锐化斧头上的时间永远不会浪费 (How and why you should tool-up: time spent sharpening your axe is never wasted) There is this old anecdote about two friend…

ListT随机返回一个

/// <summary> /// 随机返回一条数据 /// </summary> /// <param name"list"></param> /// <returns></returns> protected string GetRandomData(List<string> list) {return list.OrderBy(_ > Guid.NewGuid()).First…

微信小程序插件功能页开发详细流程

有问题可以扫码加我微信&#xff0c;有偿解决问题。承接小程序开发。 微信小程序开发交流qq群 173683895 、 526474645 &#xff1b; 正文&#xff1a; 关于新出的微信小程序插件功能页做一下记录&#xff0c;希望能帮到大家 步骤&#xff1a; 1.打开开发者工具&#x…

(拆点+最小路径覆盖) bzoj 2150

2150: 部落战争 Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 518 Solved: 298[Submit][Status][Discuss]Description lanzerb的部落在A国的上部&#xff0c;他们不满天寒地冻的环境&#xff0c;于是准备向A国的下部征战来获得更大的领土。 A国是一个M*N的矩阵&#xff0…

使用Flow检查React,Redux和React-Redux的全面指南

by Fabian Terh由Fabian Terh 使用Flow检查React&#xff0c;Redux和React-Redux的全面指南 (A comprehensive guide to type checking React, Redux, and React-Redux with Flow) This article is divided into 4 sections:本文分为4个部分&#xff1a; Type checking Redux…