在Auto.js中,可以通过设置网络请求的代理来控制代码中的数据是否走VPN和代理。以下是一个示例代码,演示如何设置代理:

// 打开VPN和代理开关
shell("settings put global http_proxy 127.0.0.1:8888", true);
shell("settings put global global_http_proxy_host 127.0.0.1:8888", true);
shell("settings put global global_http_proxy_port 8888", true);

// 发送网络请求
http.get("https://example.com", {
    headers: {
        "User-Agent": "Auto.js"
    },
    handler: function (res) {
        // 处理响应数据
        var data = res.body.string();
        toastLog(data);
    }
});

// 关闭VPN和代理开关
shell("settings delete global http_proxy", true);
shell("settings delete global global_http_proxy_host", true);
shell("settings delete global global_http_proxy_port", true);

以上代码首先打开VPN和代理开关,然后发送网络请求,最后关闭VPN和代理开关。通过设置全局的 http_proxy 和 global_http_proxy_host 和 global_http_proxy_port 属性,可以将网络请求流量重定向到指定的代理服务器。你可以根据自己的代理设置进行相应的修改。

注意:这里使用的是 Android 系统的设置命令,需要在有 Root 权限的设备上运行,或者在已经授权的 Auto.js 中运行。

希望对你有帮助


原文地址: https://www.cveoy.top/t/topic/inUq 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录