curl 是一种命令行工具

curl 是一种命令行工具,作用是发出网络请求,然后获取数据,显示在"标准输出"(stdout)上面。它支持多种协议,下面列举其常用功能。

一、查看网页源码

直接在 curl 命令后加上网址,就可以看到网页源码。以网址 www.sina.com为例(选择该网址,主要因为它的网页代码较短)。


$ curl www.sina.com

301 Moved Permanently

301 Moved Permanently


nginx

二、接口跨域问题验证

curl -i "接口地址" -H "Origin:https://test.baidu.com"
-i 参数可以显示 http response 的头信息,连同网页代码一起。-I (大写)参数则只显示 http response 的头信息。
响应头信息:

HTTP/1.1 200
Server: NRPd
Date: Thu, 15 Jul 2021 12:49:17 GMT
Content-Type: application/json;charset=UTF-8
Content-Length: 69
Connection: keep-alive
Access-Control-Expose-Headers: X-REQ-ID
X-REQ-ID: N0NggDj84aBQa9nS
Pragma: no-cache
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Cache-Control: no-cache
Cache-Control: no-store
Access-Control-Expose-Headers: UC-AUTH-CODE,UC-AUTH-MSG
UC-AUTH-CODE: 110
UC-AUTH-MSG: xxx
Access-Control-Allow-Origin: https://test.baidu.com
Access-Control-Allow-Credentials: true

响应体:

{"responseCode":"900101","responseMsg":"用户安全认证未通过"}

你可能感兴趣的:(curl 是一种命令行工具)