Requestjs重定向

时间:2015-08-13 17:28:18

标签: javascript node.js post multipartform-data

使用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默认支持重定向。预期会出现这种情况吗?

1 个答案:

答案 0 :(得分:1)

默认情况下,请求仅遵循GET重定向请求。由于您正在使用POST请求,请使用

followAllRedirects: true

关注POST请求的重定向。

  

followAllRedirects - 将非GET HTTP 3xx响应作为重定向(默认值:false)