Shadow——curl指定代理 fetch指定代理

 

curl和ts的fetch函数默认不会使用Shadow代理。如果你希望在这些工具中通过Shadow代理进行连接,你需要手动配置代理设置。

 

一、对于curl,你可以使用`--proxy`选项指定代理服务器的地址和端口。以下是通过curl命令并使用Shadow代理访问`https://api.openai.com/v1/chat/completions`的示例:

curl --proxy http://127.0.0.1:1080 https://api.openai.com/v1/chat/completions

使用了`--proxy`选项将代理服务器的地址和端口设置为`http://127.0.0.1:1080`。

你的curl命令中指定了代理使用http://127.0.0.1:1080,这是一个本地HTTP代理地址。

然后,你可以使用该代理来发送HTTPS请求到https://api.openai.com/v1/chat/completions

请确保你已经在本地启动了一个支持HTTP代理的服务,并将其监听在127.0.0.1:1080上。这样,通过该代理发送的请求将会被转发到目标网址。

 

 

二、对于ts的fetch函数,你可以使用`node-fetch`库以及`https-proxy-agent`库来设置代理代理。以下是一个使用fetch函数和Shadow代理的示例:

import fetch from 'node-fetch';
import HttpsProxyAgent from 'https-proxy-agent';

const proxyAgent = new HttpsProxyAgent('http://127.0.0.1:1080'); // 设置代理

const requestOptions = {
method: 'GET',
agent: proxyAgent,
};

const url = 'https://api.openai.com/v1/chat/completions';

fetch(url, requestOptions)
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error)); 

在这个示例中,我们使用了`https-proxy-agent`库来实例化一个代理代理,并将其传递给fetch函数的`agent`选项。确保将`http://127.0.0.1:1080`替换为你的Shadow代理的地址和端口。

使用上述方法,你可以在curl和ts的fetch函数中配置Shadow代理来进行连接。 请注意,在配置代理时,请确保合理设置代理及其合法性。

 

三、git clone 指定代理

Y:\git\github\chatgpt-web-owner>set http_proxy=http://127.0.0.1:1080
Y:\git\github\chatgpt-web-owner>echo %http_proxy%
http://127.0.0.1:1080

Y:\git\github\chatgpt-web-owner>set https_proxy=http://127.0.0.1:1080

Y:\git\github\chatgpt-web-owner>echo %http_proxy%
http://127.0.0.1:1080

Y:\git\github\chatgpt-web-owner>echo %https_proxy%
http://127.0.0.1:1080

Y:\git\github\chatgpt-web-owner>
Y:\git\github\chatgpt-web-owner>
Y:\git\github\chatgpt-web-owner>
Y:\git\github\chatgpt-web-owner>
Y:\git\github\chatgpt-web-owner>git clone https://github.com/Chanzhaoyu/chatgpt-web.git
Cloning into 'chatgpt-web'...
remote: Enumerating objects: 3192, done.
remote: Counting objects: 100% (21/21), done.
remote: Compressing objects: 100% (21/21), done.
remote: Total 3192 (delta 4), reused 7 (delta 0), pack-reused 3171
Receiving objects: 100% (3192/3192), 5.66 MiB | 1.93 MiB/s, done.
Resolving deltas: 100% (1481/1481), done.

Y:\git\github\chatgpt-web-owner>

 

posted @ 2023-07-03 17:39  会飞的斧头  阅读(389)  评论(0编辑  收藏  举报