「Curl」:修訂間差異
跳至導覽
跳至搜尋
第10行: | 第10行: | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
curl -v -X POST -H 'Content-Type: application/json' -d '{"a":"b","c":"d"}' https://httpbin.org/anything | curl -v -X POST -H 'Content-Type: application/json' -d '{"a":"b","c":"d"}' https://httpbin.org/anything | ||
</syntaxhighlight> | |||
=== File Upload === | |||
上傳檔案: | |||
<syntaxhighlight lang="bash"> | |||
curl -v -X POST -F "foo=@/home/foo/bar.png" https://httpbin.org/anything | |||
</syntaxhighlight> | </syntaxhighlight> | ||
於 2024年10月18日 (五) 00:07 的最新修訂
curl是一套工具,包括library以及command line tool。
範例
JSON
如果要POST JSON的話:
curl -v -X POST -H 'Content-Type: application/json' -d '{"a":"b","c":"d"}' https://httpbin.org/anything
File Upload
上傳檔案:
curl -v -X POST -F "foo=@/home/foo/bar.png" https://httpbin.org/anything
Proxy
指定proxy可以用--proxy
並且包含proxy需要的帳號密碼:
curl -v --proxy https://username:password@proxy.example.com:4128/ https://httpbin.org/anything
Request Header
指定referer可以用-H
:
curl -v -H "Referer: https://www.example.com/" https://httpbin.org/anything
指定User-agent可以使用-A
:
curl -v -A "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36" https://httpbin.org/anything
外部連結
- 官方網站 (英文)