xml请求
示例:
curl -k https://127.0.0.1:8080/WebService1.asmx?wsdl/method=https -X POST -H "Content-Type: text/xml;charset=utf-8" -d '<?xml version="1.0" encoding="utf-8" standalone="yes"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/"><soapenv:Header><tem:MySoapHeader><tem:HK>300000001</tem:HK><tem:HV>300000001</tem:HV></tem:MySoapHeader></soapenv:Header><soapenv:Body xsi:type="appGetStatementsNewResultBody" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><tem:AppGetStatementsNew><tem:Sdate>2022-10-01</tem:Sdate><tem:Edate>2022-10-01</tem:Edate></tem:AppGetStatementsNew></soapenv:Body></soapenv:Envelope>'
- -X <method> // 设置请求方法
- -H <header> // 设置请求头
- -D <data> // 设置请求数据(POST方法)
例子:
curl 'https://v1.hitokoto.cn/' -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36' -H 'Cookie: _ga=GA1.2.303411826.1562744042' -D 'c=b'
上面的例子表示
- 用
POST
请求https://v1.hitokoto.cn/
,由于添加了-D
参数,所以-X POST
参数可以不写 - 添加了两个
请求头
,分别是User-Agent
,和Cookie
- 添加了一个
请求数据
,c=b
。若请求数据
有多个时,用&
连接。
另外,在现代浏览器的开发者工具中,有一个很方便的功能,可以复制所请求的 curl
命令。
复制出来的结果:
curl 'https://v1.hitokoto.cn/' -H 'Connection: keep-alive' -H 'Cache-Control: max-age=0' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: zh-CN,zh;q=0.9' -H 'Cookie: _ga=GA1.2.303411826.1562744042' --compressed
当调试 api 接口出现问题时,我们就可以直接发送这段命令给其他开发者,只需粘贴到终端运行,便能知道问题所在,可以说是相当的方便。
有時一些內部使用的加密 SSL 網頁使用自簽憑證, 如果用 curl 擷取這些使用自簽憑證的 SSL 網頁內容, 會出現以下錯誤:
要避免這個情況, 需要在 curl 指令後面加上 “-k” 或 “–insecure” 參數, 這樣 curl 便不會檢查 SSL 的有效性, 例如:
1 | $ curl -k https://localhost/ |
1 | $ curl --insecure https://localhost/ |
查看公网ip
curl ifconfig.me
curl cip.cc
curl http://members.3322.org/dyndns/getip
curl icanhazip.com
-
curl icanhazip.com
-
curl ifconfig.me
-
curl curlmyip.com
-
curl ip.appspot.com
-
curl ipinfo.io/ip
-
curl ipecho.net/plain
-
curl www.trackip.net/i