Requestjs重定向

Requestjs redirection

使用 requestjs,我发送 POST multipart/form-data 请求,如下所示;

request.post({
  uri: "https://app.bom.com/items/command-export-2",
  headers: {
    "cookies": cookie,
    "Content-Type": "multipart/form-data; boundary=----WebKitFormBoundaryS4isRj4WDxhi155d"
  },
  formData: {
    wfs_id: "17767554",
    search_category: "item_number",
    search_textfield: "161337",
    kept_items_p: "0",
    kept_objects_list: "",
    search_mode: "adv",
    query_id: queryId,
    list_export_p: "1",
    all_objects_p: "0",
    item_count: itemCount,
    show_only_checked_p: "0",
    import_id: "0",
    import_list_p: "0",
    tabular_format_option: "",
    form_file_format: "0",
    csv_setting_id: "-20000",
    pdx_setting_id: "0",
    export_now_btn: "Export Now »"
  },
  jar: jar
})
.on('response', function(response) {
  log.info(response);
  log.info(jar);
})
.on('error', _error);

我收到了代码 302 的回复。我认为 requestjs 默认支持重定向。这种行为是预期的吗?

默认情况下,请求仅遵循 GET 重定向请求。由于您使用的是 POST 请求,因此请使用

followAllRedirects: true

跟随来自 POST 请求的重定向。

followAllRedirects - follow non-GET HTTP 3xx responses as redirects (default: false)