是否可以更改请求中的选项对象,这对我来说似乎不起作用。有人可以帮我弄这个吗?我正在尝试对2个不同的网址使用一个请求。
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(/[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);
});
答案 0 :(得分:2)
您只需更改对象的“url”属性
即可options.url = "http://" + lane.address + "/awp/IOTest/SSLDiagnostics/diagnostics.htm";