javascript - 根据请求更改选项对象

标签 javascript node.js request

是否可以更改请求中的选项对象,这似乎对我不起作用。有人可以帮我弄这个吗?我正在尝试对 2 个不同的 url 使用一个请求。

    var options = { url: "http://" + lane.address + "/awp/SSLDiagnostics/diagnostics.htm", timeout: interval };

if (lane.filter === "vf0")options = {url: "http://" + lane.address + "/awp/IOTest/SSLDiagnostics/diagnostics.htm", timeout: interval };

像这样使用它

request(options, function (error, response, body)
{
    if (!error && response.statusCode == 200) {
        var state;
        var cleaned = body.replace(/&#x2[0|7];|'/g, "");
        state = !("vf1" === lane.filter) ? parse_responseOnexs(cleaned) : state = "vf0" === lane.filter ? parse_responseVf0(cleaned) : parse_responseVf1(cleaned);
        if (state) {
            state_update = new lane_state(lane, '', state);
        }
        else {
            state_update = new lane_state(lane, 'Error parsing response from PLC...: ' + body, {});
        }
    }
    else {
        state_update = new lane_state(lane, 'Server is unable to connect to the PLC: ' + error, {});
        failedCount = previousFailedCount + 1;
    }
    if (failedCount != 1) {
        result_callback(state_update);
    }
    setTimeout(function () {
        poll_lanestate(lane, interval, result_callback, failedCount);
    }, interval);
});

最佳答案

您只需更改对象的“url”属性即可

options.url = "http://" + lane.address + "/awp/IOTest/SSLDiagnostics/diagnostics.htm";

关于javascript - 根据请求更改选项对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49942295/

相关文章:

php - 为 .js 和 .css 等嵌入文件设置 include_path?

node.js - 亚马逊 S3 服务器上的 Concat MP3/媒体音频文件

xml - 经典 asp 中的 System.Net.HttpWebRequest?

javascript - Kendo ui 网格命令模板点击链接功能

javascript - 地理定位 watch 不会持续触发

javascript - 仅在 JavaScript 中获取号码

node.js - 在 Web 应用程序中公开存储桶 URL 安全吗?

javascript - Sails.js 连接到 Cloud mongoDb Atlas

java - 将请求的查询字符串解析为 JSON

java - 如何解决解析 HTTP 请求 header 时出现的错误?它在什么时候发生?