成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

如何讓curl命令通過代理訪問

系統 Linux
很多 Linux 和 Unix 命令行工具使用名為 http_proxy,https_proxy,ftp_proxy 的環境變量來獲取代理信息。它允許你通過代理服務器(使用或不使用用戶名/密碼都行)來連接那些基于文本的會話和應用。本文就會演示一下如何讓 curl 通過代理服務器發送 HTTP/HTTPS 請求。

[[217533]]

我的系統管理員給我提供了如下代理信息:

  1. IP: 202.54.1.1
  2. Port: 3128
  3. Username: foo
  4. Password: bar

該設置在 Google Chrome 和 Firefox 瀏覽器上很容易設置。但是我要怎么把它應用到 curl 命令上呢?我要如何讓 curl 命令使用我在 Google Chrome 瀏覽器上的代理設置呢?

很多 Linux 和 Unix 命令行工具(比如 curl 命令,wget 命令,lynx 命令等)使用名為 http_proxyhttps_proxyftp_proxy 的環境變量來獲取代理信息。它允許你通過代理服務器(使用或不使用用戶名/密碼都行)來連接那些基于文本的會話和應用。

本文就會演示一下如何讓 curl 通過代理服務器發送 HTTP/HTTPS 請求。

 

讓 curl 命令使用代理的語法

語法為:

  1. ## Set the proxy address of your uni/company/vpn network ##
  2. export http_proxy=http://your-ip-address:port/
  3.  
  4. ## http_proxy with username and password
  5. export http_proxy=http://user:password@your-proxy-ip-address:port/
  6.  
  7. ## HTTPS version ##
  8. export https_proxy=https://your-ip-address:port/
  9. export https_proxy=https://user:password@your-proxy-ip-address:port/

另一種方法是使用 curl 命令的 -x 選項:

  1. curl -x <[protocol://][user:password@]proxyhost[:port]> url
  2. --proxy <[protocol://][user:password@]proxyhost[:port]> url
  3. --proxy http://user:password@Your-Ip-Here:Port url
  4. -x http://user:password@Your-Ip-Here:Port url

 

在 Linux 上的一個例子

首先設置 http_proxy

  1. ## proxy server, 202.54.1.1, port: 3128, user: foo, password: bar ##
  2. export http_proxy=http://foo:bar@202.54.1.1:3128/
  3. export https_proxy=$http_proxy
  4. ## Use the curl command ##
  5. curl -I https://www.cyberciti.biz
  6. curl -v -I https://www.cyberciti.biz

輸出為:

  1. * Rebuilt URL to: www.cyberciti.biz/
  2. * Trying 202.54.1.1...
  3. * Connected to 1202.54.1.1 (202.54.1.1) port 3128 (#0)
  4. * Proxy auth using Basic with user 'foo'
  5. > HEAD HTTP://www.cyberciti.biz/ HTTP/1.1
  6. > Host: www.cyberciti.biz
  7. > Proxy-Authorization: Basic x9VuUml2xm0vdg93MtIz
  8. > User-Agent: curl/7.43.0
  9. > Accept: */*
  10. > Proxy-Connection: Keep-Alive
  11. >
  12. < HTTP/1.1 200 OK
  13. HTTP/1.1 200 OK
  14. < Server: nginx
  15. Server: nginx
  16. < Date: Sun, 17 Jan 2016 11:49:21 GMT
  17. Date: Sun, 17 Jan 2016 11:49:21 GMT
  18. < Content-Type: text/html; charset=UTF-8
  19. Content-Type: text/html; charset=UTF-8
  20. < Vary: Accept-Encoding
  21. Vary: Accept-Encoding
  22. < X-Whom: Dyno-l1-com-cyber
  23. X-Whom: Dyno-l1-com-cyber
  24. < Vary: Cookie
  25. Vary: Cookie
  26. < Link: <http://www.cyberciti.biz/wp-json/>; rel="https://api.w.org/"
  27. Link: <http://www.cyberciti.biz/wp-json/>; rel="https://api.w.org/"
  28. < X-Frame-Options: SAMEORIGIN
  29. X-Frame-Options: SAMEORIGIN
  30. < X-Content-Type-Options: nosniff
  31. X-Content-Type-Options: nosniff
  32. < X-XSS-Protection: 1; mode=block
  33. X-XSS-Protection: 1; mode=block
  34. < X-Cache: MISS from server1
  35. X-Cache: MISS from server1
  36. < X-Cache-Lookup: MISS from server1:3128
  37. X-Cache-Lookup: MISS from server1:3128
  38. < Connection: keep-alive
  39. Connection: keep-alive
  40.  
  41. <
  42. * Connection #0 to host 10.12.249.194 left intact

本例中,我來下載一個 pdf 文件:

  1. $ export http_proxy="vivek:myPasswordHere@10.12.249.194:3128/"
  2. $ curl -v -O http://dl.cyberciti.biz/pdfdownloads/b8bf71be9da19d3feeee27a0a6960cb3/569b7f08/cms/631.pdf

也可以使用 -x 選項:

  1. curl -x 'http://vivek:myPasswordHere@10.12.249.194:3128' -v -O https://dl.cyberciti.biz/pdfdownloads/b8bf71be9da19d3feeee27a0a6960cb3/569b7f08/cms/631.pdf

輸出為:

Fig.01:curl in action \(click to enlarge\)

Fig.01:curl in action \(click to enlarge\)

 

Unix 上的一個例子

  1. $ curl -x http://prox_server_vpn:3128/ -I https://www.cyberciti.biz/faq/howto-nginx-customizing-404-403-error-page/

 

socks 協議怎么辦呢?

語法也是一樣的:

  1. curl -x socks5://[user:password@]proxyhost[:port]/ url
  2. curl --socks5 192.168.1.254:3099 https://www.cyberciti.biz/

 

如何讓代理設置永久生效?

編輯 ~/.curlrc 文件:

  1. $ vi ~/.curlrc

添加下面內容:

  1. proxy = server1.cyberciti.biz:3128
  2. proxy-user = "foo:bar"

保存并關閉該文件。另一種方法是在你的 ~/.bashrc 文件中創建一個別名:

  1. ## alias for curl command
  2. ## set proxy-server and port, the syntax is
  3. ## alias curl="curl -x {your_proxy_host}:{proxy_port}"
  4. alias curl = "curl -x server1.cyberciti.biz:3128"

記住,代理字符串中可以使用 protocol:// 前綴來指定不同的代理協議。使用 socks4://socks4a://socks5://或者 socks5h:// 來指定使用的 SOCKS 版本。若沒有指定協議或者使用 http:// 表示 HTTP 協議。若沒有指定端口號則默認為 1080-x 選項的值要優先于環境變量設置的值。若不想走代理,而環境變量總設置了代理,那么可以通過設置代理為空值("")來覆蓋環境變量的值。詳細信息請參閱 curl 的 man 頁 。 

責任編輯:龐桂玉 來源: Linux中國
相關推薦

2015-12-30 14:47:01

LinuxDropbox訪問

2020-10-31 08:20:39

curl命令命令行互聯網

2023-02-27 07:37:56

Curl操作SQL

2023-05-15 20:11:34

2011-09-02 11:19:11

Linuxusbnet

2021-09-30 07:03:12

gRPC服務Grpcurl

2019-12-06 09:30:55

curl命令Linux

2016-07-12 10:43:39

云計算云安全

2016-10-17 16:26:42

2015-12-15 15:09:49

Windows 10資源訪問

2023-05-24 14:58:23

2013-03-26 14:16:58

Windows 8RDP虛擬桌面

2011-08-04 09:56:04

TMG ISA新浪微博

2023-09-24 13:07:53

NginxMySQLIP

2011-08-31 10:14:36

windows7Hosts

2011-08-19 15:15:04

2018-01-24 16:30:43

Linux命令Wifi

2016-03-18 10:08:48

2024-08-05 08:24:06

java外網Nginx

2017-04-13 10:14:46

curl命令分析
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 国产精品国产精品国产专区不片 | 欧美做暖暖视频 | av黄色在线观看 | 日本久草 | 久久久精品久久久 | 人人爽人人草 | 91精品中文字幕一区二区三区 | 国产激情毛片 | 精精国产xxxx视频在线 | 自拍在线 | 久www| 日韩影院在线观看 | 特级毛片www| 亚洲欧美综合网 | 综合婷婷 | 野狼在线社区2017入口 | 亚洲免费一 | 精品久久久久久亚洲精品 | 欧美日韩综合一区 | 日产精品久久久一区二区福利 | 国产精品视频免费观看 | 欧洲成人免费视频 | 国产精品自在线 | 日韩三级一区 | 免费精品视频在线观看 | 高清视频一区二区三区 | 亚洲精品一区二区在线 | 99九色| 精品国产高清一区二区三区 | 国产99精品 | 亚洲欧美激情精品一区二区 | 久久久av一区 | 久久精品黄色 | 亚洲精品欧美精品 | 中文字幕精品一区二区三区精品 | 四色成人av永久网址 | 国产精品日本一区二区不卡视频 | 国产精品一区视频 | 玖草资源 | 欧美日韩精品一区二区三区四区 | 亚洲视频在线一区 |