首页 > 解决方案 > NodeJS:@esri/arcgis-rest-request - 如何调整 Fetch 选项?

问题描述

我希望在使用@esri/arcgis-rest-request 发出请求时调整Fetch 请求选项,但不幸的是我找不到与此相关的任何文档。

import fetch from "node-fetch";
import FormData from "isomorphic-form-data";
import arcgisRestRequest from "@esri/arcgis-rest-request";
arcgisRestRequest.setDefaultRequestOptions({ fetch, FormData });

arcgisRestRequest.request("https://www.arcgis.com/sharing/rest/info")
  .then(response => console.log(response));

使用请求方法时,我收到有关 NodeJS 服务器证书的错误:

FetchError: request to https://xxx/server/rest/self?token=xxx=json failed, reason: unable to get local issuer certificate

我想通过类似的东西:

const fetchOptions = {
  ...
  agent:new https.Agent({rejectUnauthorized: false}),
  ...
};

以避免证书错误。

我怎样才能做到这一点?

标签: javascriptnode.jsnestjs

解决方案


Looking at their code it looks like you should be able to just do

arcgisRestRequest.request(
  "https://www.arcgis.com/sharing/rest/info",
  {
    agent:new https.Agent({rejectUnauthorized: false})
  }
)
  .then(response => console.log(response));

推荐阅读