在使用 curl
命令时,如果你需要通过代理服务器进行网络请求,可以使用 -x
或 --proxy
选项来指定代理服务器。下面是使用代理的一些基本示例:
使用 HTTP 代理
如果你的代理服务器是 HTTP 代理,你可以这样使用:
1 |
curl -x http://代理服务器地址:端口 http://目标网址 |
使用 HTTPS 代理
如果你的代理服务器支持 HTTPS,使用方法类似:
1 |
curl -x https://代理服务器地址:端口 https://目标网址 |
使用 SOCKS5 代理
curl
同样支持 SOCKS4 和 SOCKS5 代理,例如使用 SOCKS5 代理:
1 |
curl -x socks5://代理服务器地址:端口 http://目标网址 |
验证代理服务器
如果你的代理服务器需要认证,可以通过在代理地址前添加用户名和密码来实现:
1 |
curl -x http://用户名:密码@代理服务器地址:端口 http://目标网址 |
请将 代理服务器地址
、端口
、用户名
、密码
和 目标网址
替换为实际使用的值。
使用配置文件
linux 下使用当前用户目录下的 .curlrc, Windows 下使用当前用户目录下的_curlrc
文件内容如下:
1 |
proxy=http://127.0.0.1:18081 |
注意事项
- 使用代理时,请确保代理服务器的地址和端口号正确无误。
- 如果代理服务器需要认证,请确保提供的用户名和密码正确。
- 有些网络环境可能会限制或阻止代理服务器的使用,请确保你有权使用指定的代理服务器。
这些是 curl
使用代理的基本方法,可以根据你的具体需求进行选择和调整。
例子
1. Windows 下获取OpenAI API 的模型列表,需要设置环境变量 OPENAI_API_KEY
1 |
curl -x http://127.0.0.1:18081 https://api.openai.com/v1/models -H "Authorization: Bearer %OPENAI_API_KEY%" |
2.linux 下获取OpenAI API 的模型列表,需要设置环境变量 OPENAI_API_KEY
1 |
curl -x http://127.0.0.1:18081 https://api.openai.com/v1/models -H "Authorization: Bearer $OPENAI_API_KEY" |
运行结果:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
{ "object": "list", "data": [ { "id": "whisper-1", "object": "model", "created": 1677532384, "owned_by": "openai-internal" }, { "id": "davinci-002", "object": "model", "created": 1692634301, "owned_by": "system" }, { "id": "gpt-3.5-turbo", "object": "model", "created": 1677610602, "owned_by": "openai" }, { "id": "dall-e-2", "object": "model", "created": 1698798177, "owned_by": "system" }, { "id": "gpt-3.5-turbo-16k", "object": "model", "created": 1683758102, "owned_by": "openai-internal" }, { "id": "tts-1-hd-1106", "object": "model", "created": 1699053533, "owned_by": "system" }, { "id": "tts-1-hd", "object": "model", "created": 1699046015, "owned_by": "system" }, { "id": "gpt-3.5-turbo-16k-0613", "object": "model", "created": 1685474247, "owned_by": "openai" }, { "id": "gpt-4-1106-vision-preview", "object": "model", "created": 1711473033, "owned_by": "system" }, { "id": "gpt-3.5-turbo-instruct-0914", "object": "model", "created": 1694122472, "owned_by": "system" }, { "id": "gpt-4-turbo", "object": "model", "created": 1712361441, "owned_by": "system" }, { "id": "gpt-3.5-turbo-instruct", "object": "model", "created": 1692901427, "owned_by": "system" }, { "id": "gpt-3.5-turbo-0301", "object": "model", "created": 1677649963, "owned_by": "openai" }, { "id": "gpt-3.5-turbo-0613", "object": "model", "created": 1686587434, "owned_by": "openai" }, { "id": "tts-1", "object": "model", "created": 1681940951, "owned_by": "openai-internal" }, { "id": "dall-e-3", "object": "model", "created": 1698785189, "owned_by": "system" }, { "id": "gpt-3.5-turbo-1106", "object": "model", "created": 1698959748, "owned_by": "system" }, { "id": "babbage-002", "object": "model", "created": 1692634615, "owned_by": "system" }, { "id": "gpt-4-turbo-2024-04-09", "object": "model", "created": 1712601677, "owned_by": "system" }, { "id": "tts-1-1106", "object": "model", "created": 1699053241, "owned_by": "system" }, { "id": "text-embedding-3-large", "object": "model", "created": 1705953180, "owned_by": "system" }, { "id": "gpt-4-0125-preview", "object": "model", "created": 1706037612, "owned_by": "system" }, { "id": "gpt-4-vision-preview", "object": "model", "created": 1698894917, "owned_by": "system" }, { "id": "text-embedding-3-small", "object": "model", "created": 1705948997, "owned_by": "system" }, { "id": "gpt-4-turbo-preview", "object": "model", "created": 1706037777, "owned_by": "system" }, { "id": "gpt-4", "object": "model", "created": 1687882411, "owned_by": "openai" }, { "id": "text-embedding-ada-002", "object": "model", "created": 1671217299, "owned_by": "openai-internal" }, { "id": "gpt-4-1106-preview", "object": "model", "created": 1698957206, "owned_by": "system" }, { "id": "gpt-3.5-turbo-0125", "object": "model", "created": 1706048358, "owned_by": "system" }, { "id": "gpt-4-0613", "object": "model", "created": 1686588896, "owned_by": "openai" }, { "id": "davinci:ft-aqwu-net:huihui-2023-04-05-17-59-44", "object": "model", "created": 1680717584, "owned_by": "aqwu-net" }, { "id": "davinci:ft-aqwu-net:nso-2023-04-06-09-11-35", "object": "model", "created": 1680772295, "owned_by": "aqwu-net" }, { "id": "davinci:ft-aqwu-net:nso-2023-04-06-10-15-20", "object": "model", "created": 1680776121, "owned_by": "aqwu-net" } ] } |
重定向使用 -L
在下载文件的时候,可能会有重定向发生,这个时候需要使用 -L 参数
1 |
curl.exe -x 127.0.0.1:18081 -kL -o "Flux\flux1-schnell-bnb-nf4.safetensors" "https://huggingface.co/silveroxides/flux1-nf4-weights/resolve/main/flux1-schnell-bnb-nf4.safetensors" |