CURL 命令总结

1 发送POST请求-注解@RequestBody

curl -X POST 'http://localhost:8888/interface_url'
-H "tenant-tag:tenant1"
-H 'Content-Type: application/json'
-d '[
    {
        "field2": "value1",
        "field2": "value2"
    },
    {
        "field2": "value1",
        "field2": "value2"
    }
]'

2 发送POST请求-注解@RequestParam

curl -X POST 'http://localhost:8888/interface_url?param1=value1¶m2=value2'
-H "tenant-tag:tenant1"
-H 'Content-Type: application/json'

3 发送GET请求-注解@RequestParam

curl -X GET 'http://localhost:8888/interface_url?param1=value1¶m2=value2'
-H "tenant-tag:tenant1"
-H 'Content-Type: application/json'

4 注解@RequestPara URL中文参数

注解@RequestPara URL中文参数要解码和编码,不然测试的过程中会出错

The valid characters are defined in RFC 7230 and RFC 3986
    org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:505)
    org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:502)
    org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
    org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:818)
    org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1627)
    org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    java.lang.Thread.run(Thread.java:745)

在线URL编码urlencode工具

https://uutool.cn/urlencode/

CURL 命令总结_第1张图片example

curl -X GET 'http://localhost:8888/interface_url?param1=value1&yourName%3D%E4%BD%A0%E7%9A%84%E5%90%8D%E5%AD%97'
-H "tenant-tag:tenant1"
-H 'Content-Type: application/json'

CURL 命令总结_第2张图片

5 postman自动生成CURL命令

和postman版本有关,我这个版本的postman生成的命令是这样的,不太正常,同事的postman生成的CURL命令是正常的。
CURL 命令总结_第3张图片
形式如 1至 4个点。

你可能感兴趣的:(Java基础,java,tomcat,servlet)