「Curl」:修訂間差異
跳至導覽
跳至搜尋
無編輯摘要 |
|||
(未顯示同一使用者於中間所作的 3 次修訂) | |||
第3行: | 第3行: | ||
== 範例 == | == 範例 == | ||
=== JSON === | |||
如果要POST JSON的話: | |||
<syntaxhighlight lang="bash"> | |||
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> | |||
=== Proxy === | |||
指定proxy可以用<code>--proxy</code>並且包含proxy需要的帳號密碼: | 指定proxy可以用<code>--proxy</code>並且包含proxy需要的帳號密碼: | ||
第9行: | 第27行: | ||
curl -v --proxy https://username:password@proxy.example.com:4128/ https://httpbin.org/anything | curl -v --proxy https://username:password@proxy.example.com:4128/ https://httpbin.org/anything | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== Request Header === | |||
指定referer可以用<code>-H</code>: | 指定referer可以用<code>-H</code>: | ||
第14行: | 第34行: | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
curl -v -H "Referer: https://www.example.com/" https://httpbin.org/anything | curl -v -H "Referer: https://www.example.com/" https://httpbin.org/anything | ||
</syntaxhighlight> | |||
指定User-agent可以使用<code>-A</code>: | |||
<syntaxhighlight lang="bash"> | |||
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 | |||
</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
外部連結
- 官方網站 (英文)