linux 服务器执行post请求 curl命令详解

2023-05-16

什么是curl?

curl是一个命令行访问URL的计算机逻辑语言的工具,发出网络请求,然后得到数据并提取出,显示在标准输出“stdout”上面,可以用它来构造http request报文,curl(CommandLine Uniform Resource Locator),即在命令行中利用URL进行数据或者文件传输。

基本语法:curl [option] [url]

实际用法

POST 请求 application/json

curl -H "Content-Type: application/json" -X POST  -d '{你的内容}' https://xxx.com/api

-H 请求头
-X 指定要使用的请求命令 POST 请求方式
-d 请求内容体 data的意思

如果遇到https访问证书的问题情况 可以使用 -l 来忽略证书问题请求

-1, --tlsv1         Use => TLSv1 (SSL)
     --tlsv1.0       Use TLSv1.0 (SSL)
     --tlsv1.1       Use TLSv1.1 (SSL)
     --tlsv1.2       Use TLSv1.2 (SSL)
     --trace FILE    Write a debug trace to the given file
     --trace-ascii FILE  Like --trace but without the hex output
     --trace-time    Add time stamps to trace/verbose output
     --tr-encoding   Request compressed transfer encoding (H)

请求就变成

curl --tlsv1 -H "Content-Type: application/json" -X POST  -d '{你的内容}' https://xxx.com/api

GET 请求 带认证token

curl -G -H 'Authorization: xxx' https://xxx.com/api

-H 请求头
-G 指定请求为GET请求
-d 请求内容体 data的意思(可以自行添加)

其他请求方式 如 POST form/data 可以使用 -F

curl -X POST -F -H 'Authorization: xxx' -d '' https://xxx.com/api

-H 请求头
-F POST form-data形式请求
-d 请求内容体 data的意思(可以自行添加)

拓展超时时间配置

--connect-timeout  <senconds> 设置连接超时
--max-time <senconds> 设置请求超时

其他详见
curl -help

Usage: curl [options...] <url>
Options: (H) means HTTP/HTTPS only, (F) means FTP only
     --anyauth       Pick "any" authentication method (H)
 -a, --append        Append to target file when uploading (F/SFTP)
     --basic         Use HTTP Basic Authentication (H)
     --cacert FILE   CA certificate to verify peer against (SSL)
     --capath DIR    CA directory to verify peer against (SSL)
 -E, --cert CERT[:PASSWD] Client certificate file and password (SSL)
     --cert-type TYPE Certificate file type (DER/PEM/ENG) (SSL)
     --ciphers LIST  SSL ciphers to use (SSL)
     --compressed    Request compressed response (using deflate or gzip)
 -K, --config FILE   Specify which config file to read
     --connect-timeout SECONDS  Maximum time allowed for connection
 -C, --continue-at OFFSET  Resumed transfer offset
 -b, --cookie STRING/FILE  String or file to read cookies from (H)
 -c, --cookie-jar FILE  Write cookies to this file after operation (H)
     --create-dirs   Create necessary local directory hierarchy
     --crlf          Convert LF to CRLF in upload
     --crlfile FILE  Get a CRL list in PEM format from the given file
 -d, --data DATA     HTTP POST data (H)
     --data-ascii DATA  HTTP POST ASCII data (H)
     --data-binary DATA  HTTP POST binary data (H)
     --data-urlencode DATA  HTTP POST data url encoded (H)
     --delegation STRING GSS-API delegation permission
     --digest        Use HTTP Digest Authentication (H)
     --disable-eprt  Inhibit using EPRT or LPRT (F)
     --disable-epsv  Inhibit using EPSV (F)
 -D, --dump-header FILE  Write the headers to this file
     --egd-file FILE  EGD socket path for random data (SSL)
     --engine ENGINGE  Crypto engine (SSL). "--engine list" for list
 -f, --fail          Fail silently (no output at all) on HTTP errors (H)
 -F, --form CONTENT  Specify HTTP multipart POST data (H)
     --form-string STRING  Specify HTTP multipart POST data (H)
     --ftp-account DATA  Account data string (F)
     --ftp-alternative-to-user COMMAND  String to replace "USER [name]" (F)
     --ftp-create-dirs  Create the remote dirs if not present (F)
     --ftp-method [MULTICWD/NOCWD/SINGLECWD] Control CWD usage (F)
     --ftp-pasv      Use PASV/EPSV instead of PORT (F)
 -P, --ftp-port ADR  Use PORT with given address instead of PASV (F)
     --ftp-skip-pasv-ip Skip the IP address for PASV (F)
     --ftp-pret      Send PRET before PASV (for drftpd) (F)
     --ftp-ssl-ccc   Send CCC after authenticating (F)
     --ftp-ssl-ccc-mode ACTIVE/PASSIVE  Set CCC mode (F)
     --ftp-ssl-control Require SSL/TLS for ftp login, clear for transfer (F)
 -G, --get           Send the -d data with a HTTP GET (H)
 -g, --globoff       Disable URL sequences and ranges using {} and []
 -H, --header LINE   Custom header to pass to server (H)
 -I, --head          Show document info only
 -h, --help          This help text
     --hostpubmd5 MD5  Hex encoded MD5 string of the host public key. (SSH)
 -0, --http1.0       Use HTTP 1.0 (H)
     --ignore-content-length  Ignore the HTTP Content-Length header
 -i, --include       Include protocol headers in the output (H/F)
 -k, --insecure      Allow connections to SSL sites without certs (H)
     --interface INTERFACE  Specify network interface/address to use
 -4, --ipv4          Resolve name to IPv4 address
 -6, --ipv6          Resolve name to IPv6 address
 -j, --junk-session-cookies Ignore session cookies read from file (H)
     --keepalive-time SECONDS  Interval between keepalive probes
     --key KEY       Private key file name (SSL/SSH)
     --key-type TYPE Private key file type (DER/PEM/ENG) (SSL)
     --krb LEVEL     Enable Kerberos with specified security level (F)
     --libcurl FILE  Dump libcurl equivalent code of this command line
     --limit-rate RATE  Limit transfer speed to this rate
 -l, --list-only     List only names of an FTP directory (F)
     --local-port RANGE  Force use of these local port numbers
 -L, --location      Follow redirects (H)
     --location-trusted like --location and send auth to other hosts (H)
 -M, --manual        Display the full manual
     --mail-from FROM  Mail from this address
     --mail-rcpt TO  Mail to this receiver(s)
     --mail-auth AUTH  Originator address of the original email
     --max-filesize BYTES  Maximum file size to download (H/F)
     --max-redirs NUM  Maximum number of redirects allowed (H)
 -m, --max-time SECONDS  Maximum time allowed for the transfer
     --metalink      Process given URLs as metalink XML file
     --negotiate     Use HTTP Negotiate Authentication (H)
 -n, --netrc         Must read .netrc for user name and password
     --netrc-optional Use either .netrc or URL; overrides -n
     --netrc-file FILE  Set up the netrc filename to use
 -N, --no-buffer     Disable buffering of the output stream
     --no-keepalive  Disable keepalive use on the connection
     --no-sessionid  Disable SSL session-ID reusing (SSL)
     --noproxy       List of hosts which do not use proxy
     --ntlm          Use HTTP NTLM authentication (H)
 -o, --output FILE   Write output to <file> instead of stdout
     --pass PASS     Pass phrase for the private key (SSL/SSH)
     --post301       Do not switch to GET after following a 301 redirect (H)
     --post302       Do not switch to GET after following a 302 redirect (H)
     --post303       Do not switch to GET after following a 303 redirect (H)
 -#, --progress-bar  Display transfer progress as a progress bar
     --proto PROTOCOLS  Enable/disable specified protocols
     --proto-redir PROTOCOLS  Enable/disable specified protocols on redirect
 -x, --proxy [PROTOCOL://]HOST[:PORT] Use proxy on given port
     --proxy-anyauth Pick "any" proxy authentication method (H)
     --proxy-basic   Use Basic authentication on the proxy (H)
     --proxy-digest  Use Digest authentication on the proxy (H)
     --proxy-negotiate Use Negotiate authentication on the proxy (H)
     --proxy-ntlm    Use NTLM authentication on the proxy (H)
 -U, --proxy-user USER[:PASSWORD]  Proxy user and password
     --proxy1.0 HOST[:PORT]  Use HTTP/1.0 proxy on given port
 -p, --proxytunnel   Operate through a HTTP proxy tunnel (using CONNECT)
     --pubkey KEY    Public key file name (SSH)
 -Q, --quote CMD     Send command(s) to server before transfer (F/SFTP)
     --random-file FILE  File for reading random data from (SSL)
 -r, --range RANGE   Retrieve only the bytes within a range
     --raw           Do HTTP "raw", without any transfer decoding (H)
 -e, --referer       Referer URL (H)
 -J, --remote-header-name Use the header-provided filename (H)
 -O, --remote-name   Write output to a file named as the remote file
     --remote-name-all Use the remote file name for all URLs
 -R, --remote-time   Set the remote file's time on the local output
 -X, --request COMMAND  Specify request command to use
     --resolve HOST:PORT:ADDRESS  Force resolve of HOST:PORT to ADDRESS
     --retry NUM   Retry request NUM times if transient problems occur
     --retry-delay SECONDS When retrying, wait this many seconds between each
     --retry-max-time SECONDS  Retry only within this period
 -S, --show-error    Show error. With -s, make curl show errors when they occur
 -s, --silent        Silent mode. Don't output anything
     --socks4 HOST[:PORT]  SOCKS4 proxy on given host + port
     --socks4a HOST[:PORT]  SOCKS4a proxy on given host + port
     --socks5 HOST[:PORT]  SOCKS5 proxy on given host + port
     --socks5-basic  Enable username/password auth for SOCKS5 proxies
     --socks5-gssapi Enable GSS-API auth for SOCKS5 proxies
     --socks5-hostname HOST[:PORT] SOCKS5 proxy, pass host name to proxy
     --socks5-gssapi-service NAME  SOCKS5 proxy service name for gssapi
     --socks5-gssapi-nec  Compatibility with NEC SOCKS5 server
 -Y, --speed-limit RATE  Stop transfers below speed-limit for 'speed-time' secs
 -y, --speed-time SECONDS  Time for trig speed-limit abort. Defaults to 30
     --ssl           Try SSL/TLS (FTP, IMAP, POP3, SMTP)
     --ssl-reqd      Require SSL/TLS (FTP, IMAP, POP3, SMTP)
 -2, --sslv2         Use SSLv2 (SSL)
 -3, --sslv3         Use SSLv3 (SSL)
     --ssl-allow-beast Allow security flaw to improve interop (SSL)
     --stderr FILE   Where to redirect stderr. - means stdout
     --tcp-nodelay   Use the TCP_NODELAY option
 -t, --telnet-option OPT=VAL  Set telnet option
     --tftp-blksize VALUE  Set TFTP BLKSIZE option (must be >512)
 -z, --time-cond TIME  Transfer based on a time condition
 -1, --tlsv1         Use => TLSv1 (SSL)
     --tlsv1.0       Use TLSv1.0 (SSL)
     --tlsv1.1       Use TLSv1.1 (SSL)
     --tlsv1.2       Use TLSv1.2 (SSL)
     --trace FILE    Write a debug trace to the given file
     --trace-ascii FILE  Like --trace but without the hex output
     --trace-time    Add time stamps to trace/verbose output
     --tr-encoding   Request compressed transfer encoding (H)
 -T, --upload-file FILE  Transfer FILE to destination
     --url URL       URL to work with
 -B, --use-ascii     Use ASCII/text transfer
 -u, --user USER[:PASSWORD]  Server user and password
     --tlsuser USER  TLS username
     --tlspassword STRING TLS password
     --tlsauthtype STRING  TLS authentication type (default SRP)
     --unix-socket FILE    Connect through this UNIX domain socket
 -A, --user-agent STRING  User-Agent to send to server (H)
 -v, --verbose       Make the operation more talkative
 -V, --version       Show version number and quit
 -w, --write-out FORMAT  What to output after completion
     --xattr        Store metadata in extended file attributes
 -q                 If used as the first parameter disables .curlrc
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

linux 服务器执行post请求 curl命令详解 的相关文章

  • NVIDIA Jetson Xavier NX禁用上电自启,使用按键开关机

    NVIDIA Jetson Xavier NX禁用上电自启 xff0c 使用按键开关机 文章目录 NVIDIA Jetson Xavier NX禁用上电自启 xff0c 使用按键开关机前言一 原理二 拓展 前言 NX默认上电自启 xff0c
  • Linux系统设置共享文件夹

    Linux系统设置共享文件夹 文章目录 Linux系统设置共享文件夹一 设置原理二 设置步骤1 安装samba2 创建 设置共享文件夹 三 测试 一 设置原理 基于Ubuntu16 04 xff0c 采用在线安装samba库的方式设置共享文
  • Linux:复位USB设备

    Linux xff1a 复位USB设备 文章目录 Linux xff1a 复位USB设备前言一 基本原理二 代码实例总结 前言 在Ubuntu16 04下开发SDR设备数据处理程序时 xff0c msi sdr设备有时运行几个小时后就会出现
  • Ubuntu Terminal终端默认常用快捷键总结

    Ubuntu Terminal终端默认常用快捷键总结 Ubuntu Terminal终端快捷键默认设置如下 xff0c 不同的发行版本可能有所出入 xff0c 以下快捷键在Ubuntu18 04LTS下可用 1 文件 快捷键说 明Ctrl
  • 基于c++ boost库实现进程管理

    基于c 43 43 boost库实现进程管理 1 前言 基于c 43 43 boost库与Terminator终端 xff0c 实现启动进程 进程运行状态监听 自动重启进程 杀死进程 设置进程环境变量等基础功能 2 原理 启动 杀死进程基于
  • 【RT-Thread】UART 设备源码分析

    官网介绍 I O 设备模型框架如下图 xff1a 但看到官网写道 设备驱动层是一组驱使硬件设备工作的程序 xff0c 实现访问硬件设备的功能 它负责创建和注册 I O 设备 xff0c 对于操作逻辑简单的设备 xff0c 可以不经过设备驱动
  • 基于c++ boost实现阻塞式ping指定IP

    基于c 43 43 boost实现阻塞式ping指定IP 1 前言 在实际业务场景中 xff0c 可能需要阻塞式检测目标IP连通性 xff0c 本程序基于c 43 43 boost库实现了一个简易的阻塞式ping指定IP例子 2 原理 在循
  • ROS_PACKAGE_PATH相关问题

    在ROS进行跨文件调用功能包时遇到报错 Resource not found The following package was not found span class token keyword in span span class t
  • 基于python批量调整图像大小

    前言 在写论文的时候常常因为截图的尺寸大小不一样 xff0c 导致图片排版很难受 xff0c 在word中又不会批量修改 xff0c 用下面的代码可以批量处理修改成一样的尺寸哦 xff01 代码如下 xff1a 在本文中 xff0c 我将向
  • PX4:【启动流程】

  • 线程池和多线程的区别

    线程池的概念 线程池大类总共分为4种 fixThreadPool 正规线程 xff08 传统线程池 xff09 cacheThreadPool 缓存线程池singleThreadPoll 单线程线程池 xff08 单例线程池 xff09 S
  • C++ libcurl Digest Auth

    C 43 43 libcurl Digest Auth postman操作如下 xff1a 附认证原理如下 xff1a MD5 md5 span class token punctuation span string HA1 span cl
  • 如何安装postman(超简单)

    方法一 xff1a xff08 官网下载 xff09 1 打开https www crx4chrome com crx 1058 2 稍微往下微微一拉就出现 Download crx file from Crx4Chrome gt 的选择
  • 转 curl 参数大全

    curl是一个非常实用的 用来与服务器之间传输数据的工具 xff1b 支持的协议包括 DICT FILE FTP FTPS GOPHER HTTP HTTPS IMAP IMAPS LDAP LDAPS POP3 POP3S RTMP RT
  • DataX mysql同步到mysql

    使用Datax web 创建同步任务 准备工作 创建数据源 配置数据库相关信息 创建执行器 配置执行器执行地址相关信息 1 构建reade 1 1 SQL语句 xff08 querySql xff09 在json文件中此部分配置就是 que
  • MQTT协议简介

    目录 MQTT协议简介一 MQTT协议特点1 1 发布和订阅1 2 QoS Quality of Service levels 二 MQTT数据包结构2 1 MQTT固定头2 2 MQTT可变长 Variable header 2 3 消息
  • vins位姿图优化

    我们 的滑动窗口和边缘化方案限制了计算的复杂性 xff0c 但也给系统带来了累积漂移 更确切地说 xff0c 漂移发生在全局三维位置 x y z 和围绕重力方向的旋转 yaw 为了消除漂移 xff0c 提出了一种与单目VIO无缝集成的紧耦合
  • 基于STM32开发板实现温湿度传感数据采集

    一 实验要求 本实验将选用STM32F407ZGT6开发板进行项目开发 xff0c 选用的传感器为DHT11温湿度传感器 传感器将采集到的数据传输到STM32 xff08 MCU xff09 主控进行数据处理 xff0c 最后通过串口打印出
  • 相机成像模型、内参矩阵、外参矩阵

    相机针孔成像模型 基本的小孔成像过程 xff1a X坐标系是针孔所在坐标系 xff0c Y坐标系为成像平面坐标系 xff0c P为空间一点 xff0c 小孔成像使得P点在图像平面上呈现了一个倒立的像 xff0c 俯视图如下 xff1a 由三
  • 韦东山学习笔记——UART(串口)的使用

    基于jz2440的串口使用 搬砖的文章概述UART的发送和接收串口之间的数据传输UART的用途串口的数据帧参数说明起始位数据位奇偶校验位停止位波特率 怎么发送一字节数据 xff0c 比如 A UART的优缺点优点缺点 UART相关配置寄存器

随机推荐

  • C++源文件的编译流程简介

    概述 C 43 43 C源文件 xff0c 包含 c h cpp hpp等格式的文件 xff0c 经过预处理 编译 汇编 链接后 xff0c 形成可执行文件 xff0c 也就是 exe文件 以一个简单项目MyProject为例 xff0c
  • 无法修正错误,因为您要求某些软件包保持现状,就是它们破坏了软件包间的依赖关系

    使用 sudo apt get install 安装软件时 xff0c 出现错误 无法修正错误 xff0c 因为您要求某些软件包保持现状 xff0c 就是它们破坏了软件包间的依赖关系 错误的主要原因是 xff0c 系统中已经安装了被依赖的包
  • kalibr工具的编译与安装

    安装 kalibr提供了两种安装使用的方法 一 直接使用打包好的程序 下载地址 xff0c 选择CDE packages下载 xff08 需要访问Google xff09 使用注意事项 xff1a 只有64位系统可以使用 二 源码编译 安装
  • TCP/IP协议栈协议头

    目录 OSI与TCP IP模型UDP发送数据过程以太网协议头IP协议头UDP协议头UDP包 OSI与TCP IP模型 UDP发送数据过程 以太网协议头 把上面的以太网头用一个结构体表示如下 xff1a span class token ma
  • VLAN标签

    大家好呀 xff0c 我是请假君 xff0c 今天又来和大家一起学习数通了 xff0c 今天要分享的知识是VLAN标签 我们知道 xff0c 以太网交换机根据MAC地址表来转发数据帧 MAC地址表中包含了端口和端口所连接终端主机MAC地址的
  • fastjson的一些用法

    一般情况下 xff0c 在进行redis集群写入时 xff0c 使用jedisCluster set key value value为String类型 xff0c 那么就用到了fastjson进行序列化 以下是一些要点 xff1a 1 序列
  • 【视觉SLAM十四讲】第12讲 回环检测

    12 1 回环检测概述 前面已经介绍过了前端和后端 xff0c 前端用于特征点的提取以及轨迹 地图的初始值 xff0c 而后端负责对这部分数据进行优化 考虑到误差的存在 xff0c 每一个时刻存在的误差会不断累积 xff0c 从而产生累积误
  • LVGL——PC模拟器仿真模拟+VS2017

    目录 LVGL介绍移植说明资源下载环境搭建编译运行 本文只针对当时的LVGL v7 xff0c LVGL迭代过程中变化较大 xff0c 部分接口有可能做调整 本文仅供参考 LVGL介绍 官网 xff1a https lvgl io 官方在线
  • LVGL 优化帧率技巧

    目录标题 前文未优化版本LVGL帧率限制刷屏方法效率代码优化等级编译器版本LVGL显存单buffer非全尺寸双buffer全尺寸双buffer 本文只针对当时的LVGL v7 xff0c LVGL迭代过程中变化较大 xff0c 部分接口有可
  • CMAKE 里PRIVATE、PUBLIC、INTERFACE属性示例详解

    闲扯 cmake 里面target include directories xff0c target link libraries这两个命令里面有三种属性PRIVATE PUBLIC INTERFACE cmake PRIVATE PUBL
  • C++11 返回值优化、移动语义及函数返回值构造的重载决议

    局部变量unique ptr能否作为返回值 记得自己之前在哪写过一篇返回值优化的博客 xff0c 翻了半天csdn xff0c 居然没找到 xff0c 也不知道写在哪了 被问到一个unique ptr 局部变量能不能做返回值的问题 xff0
  • C++ 面试八股分享

    一年半 xff0c 估计又要跳槽了 xff0c 本来还想再积累一两年的 xff0c 结果公司业务线调整 xff0c 同部门三四个同事n 43 1裁了 xff0c 我也要换工作内容 xff0c 现在在来这么一出 xff0c 就准备骑驴找马 x
  • c++ makefile + clangd 生成 compile_command.json

    补充vscode 43 clangd 开发 c c 43 43 一个项目用makefile管理 xff0c 工程很大 xff0c vscode的ms cpp tools代码跳转功能基本处于残废状态 xff0c 有想将makefile 迁移至
  • stm32 串口+DMA+环形FIFO缓存收发数据

    cos环境例程 freertos环境例程 重要几点 1 配置DMA xff0c 串口及环形buff之间的关系 xff1b 2 USART IT IDLE空闲中断接收完一帧数据 xff0c 处理环形buff入口指针 通知用户程序接收完一次数据
  • VScode 中 C或C++ 结构体提示,代码补全不准确的 解决方案

    1 找到项目工作区的 settings json文件 2 修改 C Cpp intelliSenseEngine Tag Parser 为 C Cpp intelliSenseEngine Default 解释 Tag Parser 提供非
  • C/C++ 避免重复定义

    加入宏定义 第一种 xff1a span class token macro property span class token directive keyword ifndef span STUDENT H span span class
  • vscode文件标签栏显示多行

    设置步骤 xff1a 按下 ctrl 43 shift 43 p xff0c 如下图 xff1a 输入 open workspace settings xff0c 打开工作区设置 输入 workbench editor wrapTabs x
  • ::在C++中的意思

    表示作用域 xff0c 和所属关系 class A int A test 表示test是属于A类的 关于 的具体解析 xff1a 是运算符中等级最高的 xff0c 它分为三种 1 global scope 全局作用域符 xff09 xff0
  • 【Linux问题解决】操作系统用C语言多线程编程 对‘pthread_create’未定义的引用 报错解决办法

    操作系统用C语言多线程编程 对 pthread create 未定义的引用 报错解决办法 今天写操作系统作业 在Ubuntu Linux系统中用C语言编写多线程程序 在命令行进行编译 没通过编译 报错如下 xff1a In file inc
  • linux 服务器执行post请求 curl命令详解

    什么是curl xff1f curl是一个命令行访问URL的计算机逻辑语言的工具 xff0c 发出网络请求 xff0c 然后得到数据并提取出 xff0c 显示在标准输出 stdout 上面 xff0c 可以用它来构造http request