文章目录

  • 一、环境准备
  • 二、Curl使用教程
  • 三、测试curl DELETE、PUST、POST的Request
    • 1.http格式
    • 2.命令测试
  • 四、https ssl/tls相关内容

一、环境准备

ubuntu:20.04
nodejs:v10.19.0,安装在了sudo用户下
node:v19.0.0,安装在了当前用户下
nodejs就是node,node就是nodejs

  • nodejs安装(找个不装也没关系,因为程序运行在普通用户下面)
(1)使用ubuntu自带的apt-get安装(安装后的版本低,但是可以用,根据报错选择升级node还是nodejs)
sudo apt update
sudo apt install nodejs npm
在 Ubuntu 20.04 软件源中的 Node.js 版本是10.19.0,这是一个长期版本。(2)从 NodeSource 中安装 Node.js 和 np
NodeSource 软件源提供了以下版本:
v14.x - 最新稳定版
v13.x
v12.x - 最新长期版本
v10.x - 前一个长期版本以 sudo 用户身份运行下面的命令(如果你需要另外的 Node.js 版本,例如12.x,将setup_14.x修改为setup_12.x)
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -安装 Node.js 和 npm:
sudo apt install nodejs验证
sudo node --version安装开发工具:
sudo apt install build-essential

nodejs 软件下载源:https://mirrors.huaweicloud.com/nodejs/

eg:curl -Lf https://mirrors.huaweicloud.com/nodejs/v16.17.0/node-v16.17.0-linux-x64.tar.xz|tar -Jx
  • node安装(一般安装方式参考找个就行)
从 NVM 安装 Node.js 和 npm
使用 NVM,你可以随时安装或者卸载任何你想要使用或者测试的 Node.js版本。
sudo apt update
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
source ~/.bashrc
nvm --versionnvm ls-remote##[version.number]是上面显示的内容
nvm install [version.number]script_wang@master:~/ota/curl$ nvm ls
->      v10.9.0v19.0.0如果你想修改当前使用的版本,输入:
nvm use 12.16.3想要修改默认的 Node.js 版本,运行下面的命令:
nvm alias default 12.16.3

二、Curl使用教程

curl 的用法指南
curl http请求基本用法

三、测试curl DELETE、PUST、POST的Request

Curl Get

curl -X "GET" <URL>

Curl DELETE Request Syntax

curl --request "DELETE" <URL>
curl -X "DELETE" <URL>

install the json-server library using the NPM package manager

(1)sudo npm install -g json-server(2)The file represents a mock database of people with unique IDs and names.
cat database.json
{"people": [
{"id": 1,
"name": "Matthew"
},
{"id": 2,
"name": "Mark"
},
{"id": 3,
"name": "Luke"
}
]
}(3)Run the following command to start the server:
json-server --watch database.json

(4)The server starts locally, listing the following two pages:
可以看到如下内容:

(5)In a new terminal tab, send a DELETE request using curl:

curl -X "DELETE" 'http://localhost:3000/people/3'



1.http格式

  • Content-Length:22指的是user=jeffrey&pwd=1234 这个内容长度,
  • HttpServer(Python版本):post_data = self.rfile.read(content_length) ,这个是读取body体里面的内容就是user=jeffrey&pwd=1234
POST /reg.jsp HTTP/ (CRLF)
Accept:image/gif,image/x-xbit,... (CRLF)
...
HOST:127.0.0.1:8080 (CRLF)
Content-Length:22 (CRLF)
Connection:Keep-Alive (CRLF)
Cache-Control:no-cache (CRLF)
(CRLF)         //该CRLF表示消息报头已经结束,在此之前为消息报头
user=jeffrey&pwd=1234  //此行以下为提交的数据
  • GET和POST区别是GET没有body体,他所有的参数都是在url中传入的
发送get请求
http://127.0.0.1:8080?user=jeffrey&pwd=1234收到就是GET /?user=jeffrey&pwd=1234 HTTP/1.1..
Host: 127.0.0.1:8080..
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0)

2.命令测试

测试POST

curl -H "Content-Type: application/json" -X POST -d "{\"abc\":123,\"name\":\"wangji\"}" "http://localhost:3000/people"

-d,即指定body里面的参数,参数的数据,需要使用双引号,json里的双引号使用反斜杠转义才可以
-X:指定http请求的方法。
默认是使用POST,可以省略-X参数。
json数据放在一个文件里:curl -H “Content-Type: application/json” -X POST -d @test.json URL
新建一条记录的话就用post,
更新一条记录的话就用put.

测试GET

##错误,必须增加-o参数,否则有error
##curl -X GET XXX -o XXX.file   等价于wgetcurl -X GET http://localhost:12345/objects/03/d78abbe32b246a24bc9a58b6f9a888cd35beb4ab1eed743d7a6c0a5d5c3011.filez##OK
curl -X GET http://localhost:12345/objects/03/d78abbe32b246a24bc9a58b6f9a888cd35beb4ab1eed743d7a6c0a5d5c3011.filez -o test.file

查看头信息和内容

  • 如果要连同头信息一起返回,可以加上-i参数(默认就加上了-X GET参数)
curl -i  http://localhost:12345/tmp仅显示头部信息
curl -I  http://localhost:12345/tmp

测试PUT

curl -H "Content-Type: application/json" -X PUT -d "{\"abc\":123,\"name\":\"wangji\"}" "http://localhost:3000/people/2"

测试POST

  • -H指定head中多个参数,-d指定body内容
curl -X POST -H "Content-Type: application/octet-stream" -H "content-length:6"  http://localhost:12345/wangji.txt -d "123456"

四、https ssl/tls相关内容

  • 基础内容:一篇文章看明白 HTTP,HTTPS,SSL/TLS 之间的关系

  • 参考:openssl实现双向认证教程(服务端代码+客户端代码+证书生成)

  • 参考:如何在 Ubuntu 20.04 上安装 Node.js 和 npm,How to Update Node.js to the Latest Version in 2022
    How to Update Node.js to Latest Version {Linux, Windows, and macOS},Send a curl DELETE Request {With Example},curl命令发送JSON数据,curl命令请求网页和API参数详解,利用Python 搭建HttpServer(二),curl命令及其API 的使用

使用curl测试nodejs的http server相关推荐

  1. socke5 使用curl 测试_命令行测试WebSocket

    使用命令测试WebSocket Linux环境下,分别使用curl和wscat命令测试websocket连接. 前言 有时候我们需要从后台验证WebSocket连接是否正常,判断防火墙是否开通,反向代 ...

  2. linux测试网页装载时间,使用curl测试web页面响应加载速度

    curl -o /dev/null -s -w %{http_code}:%{http_connect}:%{content_type}:%{time_namelookup}:%{time_redir ...

  3. Linux ping ipv66,IPV6的测试-ipv6网卡配置-ipv6的nginx配置-ipv6的ping测试-ipv6的curl测试...

    1. 首先你的网络要先支持ipv6 centos 下ipv6 配置 vim /etc/sysconfig/network-scripts/ifcfg-eth0 添加类似: IPV6INIT=yes I ...

  4. 关于 curl: (52) Empty reply from server 问题的一种解决方案

    一.问题描述   最近在 K8s 上面部署了一个应用,应用 Container 的 Command 中包含需要使用 curl -F file=@"filename" 来上传文件的命 ...

  5. php curl dns解析,curl测试dns解析时间及tcp连接时间

    1.用Linux下的curl命令测量网络请求(分号是分隔符,可以是其他符号): curl -o /dev/null -s -w %{time_connect}:%{time_starttransfer ...

  6. curl测试返回时间

    curl测试返回时间 curl -o /dev/null -s -w '%{time_connect}:%{time_starttransfer}:%{time_total}\n' 'www.baid ...

  7. curl: (52) Empty reply from server

    curl --socks5 127.0.0.1:1080 http://httpbin.org/ip curl: (52) Empty reply from server 代码显示:来自服务器的空回复

  8. docker安装ElasticSearch8.1.0错误curl: (52) Empty reply from server的处理方法

    启动:设置端口,配置内存大小 docker run -d --name ES8 -p 9200:9200 -p 9300:9300 -e "discovery.type=single-nod ...

  9. OSS: cURL error: Empty reply from server (52)

    环境: PHP7.2 .TP6.OSS-sdk 背景: 在项目中,有一个需求是上传图片,由于图片比较大,所以使用内部的一套压缩图片逻辑后,再上传到阿里云的oss文件存储服务中,于是碰到一个问题,上传图 ...

最新文章

  1. python恶搞小程序-知道了这个,你也能写出 Python 趣味小程序
  2. 揭秘TensorFlow:Google开源到底开的是什么?
  3. 未来十年,人人有望在家远程办公?
  4. python---保留两位小数
  5. java 泛型示例_Java泛型示例教程–泛型方法,类,接口
  6. windows录屏_工具推荐:这些录屏软件既免费又好用
  7. 【Python数据分析】假设检验的基本思想、原理和步骤
  8. golang模拟新浪微博登录
  9. php获取文章内容,php文章内容抓取
  10. excel提取数字的方法
  11. 微信小程序 MinUI 组件库系列之 loadmore 页底组件
  12. gossip algorithms
  13. PrimeNG之FileUpload
  14. 基于 Stable Diffusion 一键 AI 作画:什么“小镇做题家”?人人都是艺术家
  15. python中breakpoint什么意思_breakpoint() Python 内置函数
  16. html 透明层禁止点击事件,(转)CSS3之pointer-events(屏蔽鼠标事件)属性说明
  17. 有能干到退休的程序员吗?
  18. 2021夏魔训作业 第三天 2021-07-28
  19. 利用给定公式和身高预测方法对你的身高进行预测
  20. ubuntu 安装scrapy error :wisted/test/raiser.c:4:20: fatal error: Python.h: No such file or directory

热门文章

  1. 推荐轻量级Excel工具easyexcel
  2. 机械制造与自动化专业学c语言吗,2019机械制造及其自动化专业怎么样、学什么、前景好吗...
  3. lay和lied_lay和lie的区别?
  4. 花椒,映客这种直播app怎么做
  5. Android 4.4.2系统无法使用QQHD的解决方法
  6. yota3墨水屏调节对比度_Yota3墨水屏投屏
  7. WinDbug 查找调试程序内存溢出点
  8. 将进酒计算机应用技术学院信息门户,智慧校园信息门户
  9. 2021年中国新能源汽车产销及公共充电桩数量现状分析[图]
  10. 函数式语言(function language)