首页 > 系统相关 >curl在window及linux中的使用及区别

curl在window及linux中的使用及区别

时间:2024-03-26 13:29:25浏览次数:24  
标签:form curltest 8090 -- who window linux curl 请求

目录

内容介绍

测试一(GET,application/json)

测试二(GET,x-www-form-urlencoded)

测试三(POST,FORM-DATA)

测试四(POST,x-www-form-urlencoded)

总结


内容介绍

注:通过实际测试,摆出在linux环境与windows环境下系统使用curl的不同之处
注:测试工具:ApiFox、cmd命令行、git bash命令行、idea spring boot web服务端
注:测试使用的curl可在这里生成
在这里插入图片描述


注:测试url。包含请求头、请求体、请求类型、请求url、换行符

一、测试一(GET,application/json)

测试内容:GET请求, json请求体, 带请求头

# linux 环境使用
curl --location --request GET 'http://localhost:8090/test/curltest/getRequest' \
--header 'User-Agent: Apifox/1.0.0 (https://apifox.com)' \
--header 'Content-Type: application/json' \
--data-raw '{
    "name":"i am aliens"
}'
# windows环境使用
curl --location --request GET "http://localhost:8090/test/curltest/getRequest" ^
--header "User-Agent: Apifox/1.0.0 (https://apifox.com)" ^
--header "Content-Type: application/json" ^
--data-raw "{\"name\":\"i am aliens\"}"

注:请求后返回值
git bash
在这里插入图片描述
cmd
在这里插入图片描述

归纳

注:字符的处理

key word举例windowslinux
urlhttp://localhost:8090/test/curltest/getRequest使用了双引号包裹使用了单引号包裹
换行符^反斜杠(\)上标(^)
请求体data-raw除包裹字符串使用双引号外,json中key和value的双引号还需要使用反斜杠进行转义包裹字符串使用单引号, json内部双引号不用处理

二、测试二(GET,x-www-form-urlencoded)

测试内容:GET请求,form请求参数(Content-Type: x-www-form-urlencoded), 带请求头

# linux环境
curl --location --request GET "http://localhost:8090/test/curltest/getRequest2?who=aliens" ^
--header "User-Agent: Apifox/1.0.0 (https://apifox.com)" ^
--header "Content-Type: x-www-form-urlencoded"
# windows环境
curl --location --request GET 'http://localhost:8090/test/curltest/getRequest2?who=aliens' \
--header 'User-Agent: Apifox/1.0.0 (https://apifox.com)' \
--header 'Content-Type: x-www-form-urlencoded'

git bash
在这里插入图片描述
cmd在这里插入图片描述

归纳

注:字符的处理

key word举例windowslinux
url?paran=valuehttp://localhost:8090/test/curltest/getRequest2?who=aliens没有区别没有区别
urlhttp://localhost:8090/test/curltest/getRequest使用了双引号包裹使用了单引号包裹
换行符^反斜杠(\)上标(^)

三、测试三(POST,FORM-DATA)

测试内容:POST请求,form请求参数(Content-Type: form-data), 带请求头

# linux环境
curl --location --request POST 'http://localhost:8090/test/curltest/getRequest3' \
--header 'User-Agent: Apifox/1.0.0 (https://apifox.com)' \
--form 'who="aliens"'
# windows环境
curl --location --request POST "http://localhost:8090/test/curltest/getRequest3" ^
--header "User-Agent: Apifox/1.0.0 (https://apifox.com)" ^
--form "who=\"aliens\""

git bash
在这里插入图片描述

cmd
在这里插入图片描述

归纳

注:字符的处理

key word举例windowslinux
urlhttp://localhost:8090/test/curltest/getRequest使用了双引号包裹使用了单引号包裹
换行符^反斜杠(\)上标(^)
请求体form-data除包裹字符串使用双引号外,key和value的双引号还需要使用反斜杠进行转义包裹字符串使用单引号, key值不做处理, value值使用双引号

四、测试四(POST,x-www-form-urlencoded)

测试内容:POST请求,form请求参数(Content-Type: form-data), 带请求头

# linux环境
curl --location --request POST 'http://localhost:8090/test/curltest/getRequest3' \
--header 'User-Agent: Apifox/1.0.0 (https://apifox.com)' \
--data-urlencode 'who=aliens'
# windows环境
curl --location --request POST "http://localhost:8090/test/curltest/getRequest3" ^
--header "User-Agent: Apifox/1.0.0 (https://apifox.com)" ^
--data-urlencode "who=aliens"

git bash
在这里插入图片描述cmd
在这里插入图片描述

归纳

注:字符的处理

key word举例windowslinux
urlhttp://localhost:8090/test/curltest/getRequest使用了双引号包裹使用了单引号包裹
换行符^反斜杠(\)上标(^)
请求体x-www-form-urlencoded没有区别没有区别

总结

1. 汇总
请求类型key word举例windowslinux
*urlhttp://localhost:8090/test/curltest/getRequest使用了双引号包裹使用了单引号包裹
*换行符^反斜杠(\)上标(^)
*请求体data-raw(json)除包裹字符串使用双引号外,json中key和value的双引号还需要使用反斜杠进行转义包裹字符串使用单引号, json内部双引号不用处理
GET请求体url?paran=value(url上的参数)没有区别没有区别
POST请求体x-www-form-urlencoded(编码的参数)没有区别没有区别
2. 学会了解不同

注:如果使用apifox生成业务代码curl命令行的方式可以解决在不同系统之间使用的目的。但为了方便我们自己在修改参数时可以灵活运用不同系统之间的特性,了解他们之间的区别也很重要。知己知彼,百用不怠

3. 服务端代码
package com.home.api;

import com.home.entity.RequestDTO;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("curltest")
public class CurlTestController {

    @GetMapping("getRequest")
    public ResponseEntity getRequest(HttpServletRequest request
            , @RequestBody RequestDTO requestDTO
                                     , @RequestHeader("User-Agent") String userAgent
    ) throws InterruptedException {
        System.out.println("requestDTO: "+requestDTO.toString());
        System.out.println("userAgent: "+userAgent);
        return ResponseEntity.success();
    }

    @GetMapping("getRequest2")
    public ResponseEntity getRequest2(HttpServletRequest request
            , @RequestHeader("User-Agent") String userAgent
            , @RequestParam("who") String who
    ) throws InterruptedException {
        System.out.println("userAgent: "+userAgent);
        System.out.println("who: "+who);
        return ResponseEntity.success();
    }
	 /** form-data, x-www-form-urlencoded都可以使用 */
    @PostMapping("getRequest3")
    public ResponseEntity getRequest3(HttpServletRequest request
            , @RequestHeader("User-Agent") String userAgent
            , @RequestParam("who") String who
    ) throws InterruptedException {
        System.out.println("userAgent: "+userAgent);
        System.out.println("who: "+who);
        return ResponseEntity.success();
    }
}

标签:form,curltest,8090,--,who,window,linux,curl,请求
From: https://blog.csdn.net/u014642921/article/details/136560086

相关文章

  • Linux(2)系统基本操作-Mysql数据库原生安装_Mysql常用命令_安装和使用过程常用问题
    二、Linux系统基本操作1、查询centos版本[root@host-10-150-223-171~]#uname-aLinuxhost-10-150-223-1713.10.0-957.el7.x86_64#1SMPThuNov823:39:32UTC2018x86_64x86_64x86_64GNU/Linux[root@host-10-150-223-171~]#cat/etc/redhat-releaseCentO......
  • linux下的mysql的安装方式--yum--二进制
    linux下的mysql的安装方式--yum--二进制1.yum安装yum方式wgethttp://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpmrpm-ivhmysql-community-release-el7-5.noarch.rpmyum-yinstallmysql-community-serversystemctlstartmysqlsystemctlstatusm......
  • Linux常用命令介绍
    Linux常用命令介绍Linux中的命令非常多,但是玩过Linux的人也从来不会因为Linux的命令如此之多而烦恼,因为我们只需要掌握我们最常用的命令就可以了。因为不想在使用时总是东查西找,所以在此总结一下,方便一下以后的查看。下面就说说我最常用的Linux命令。1、cd命令这是一......
  • Linux命令:lsof - 列出打开的文件及其信息
    lsof命令是listopenfiles的缩写,该命令用于列出当前系统上所有已经打开的文件。Linux系统一切皆文件,不仅仅包括普通的数据文件,还有网络套接字、设备文件、管道、命名空间等常用参数:-a:逻辑AND,多个-lsof选项之间需满足所有条件。-b:显示IPv4/IPv6缓存和统计信息。-c<进程名......
  • 【linux】Centos7 手动编译安装 cmake-3.28.4
    简介1、移除原来的cmake版本yumremovecmake-y2、下载cmake-3.28.4.tar.gz安装包并解压wgethttps://cmake.org/files/v31、移除老版本cmake版本并安装依赖包yumremovecmake-y;yuminstall-ygccgcc-c++makeautomakeopensslopenssl-devel2、下载cmake-3.7.2.tar.gz......
  • Linux命令:tcpdump - 网络分析
    tcpdump是一个功能强大的命令行网络协议分析器。主要功能:数据包捕获(抓包)数据包过滤数据分析网络故障排除和诊断常用选项-i:指定要监听的网络接口-D:列出可用于抓包的接口-s:设置抓取的数据包长度,超过这个长度的部分会被截断-c:指定要抓取的数据包的数量-w:将抓包数据保存......
  • Linux用户及用户组管理
    用户:UID(userid)多用户多任务:用户组:GID(groupid)用户创建用户的分类:管理员:root  0     655350普通用户:1-65535        系统用户:1-999(Centos7)1-499        登录用户:1000500     ......
  • Linux常用命令
    Linux常用命令介绍Linux系统中有很多命令,以下是一些常用的Linux命令列表:1、文件和目录操作命令:●ls:列出目录内容●cd:切换目录●pwd:显示当前工作目录●mkdir:创建新目录●rm:删除文件或目录●cp:复制文件或目录●mv:移动文件或目录●touch:创建......
  • Windows 10无法登录Xbox及其附属产品(包括但不限于Game Bar,Minecraft Launcher)
     1. 问题描述:打开Xbox(如下图) 或GameBar(如下图)  后,单击登录,会弹出一个窗口,印有自己账户的头像,下方一行小字“欢迎回来,$昵称$”,如下图所示:  单击唯一的绿色按钮“现在就开始吧”,该窗口消失,马上又回到点击登录前的界面。循环尝试结果都不变。2.解决方法第一步......
  • 工作中总结的30个常用Linux指令,实在记不住就别硬记了,看这篇就够了
    写在开头最近发现自己记忆力严重下滑,很多sql命令,linux命令都记不住,特别是linux命令,很多命令参数很多,一段时间不用,再去使用就需要从网上重查了,很烦人,为此花了一些时间把之前笔记中的Linux命令给整理了一下,汇总出30个常用的分享出来,下次再想不起来直接看这篇文章就行了。1、Linux......