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
。
二、对于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代理来进行连接。 请注意,在配置代理时,请确保合理设置代理及其合法性。