从这里处理X-Request-ID请求标头,地图路由JavaScript API

发布于 2025-02-01 19:40:18 字数 607 浏览 1 评论 0原文

在这里迁移从7到V8迁移。需要在请求标题中设置X-Request-ID并从响应中读取相同的内容。

版本7 中的旧实现:将“ requestId”作为查询参数发送并从“ wendment.metainfo.requestid”节点中读取响应中的节点

router.calculateRoute(
    {
        ...
        "requestId": "Route_1"
    },
    CallBackFn,
    function (error) {
      alert(error.message);
    }
);

试图在版本v8中设置如下:

_platform = new H.service.Platform({
      apikey: _appkey,
    });
router = _platform.getRoutingService(null, 8);
router.i = {"X-Request-ID": "Route_1"}

从上面的代码中,能够设置请求标题。但无法从回调功能中读取响应标头

Migrating Here maps RoutingAPI from 7 to V8. Need to set X-Request-Id in request header and read the same from response.

Old implementation in version 7: sending "requestId" as query param and reading the value from "response.metaInfo.requestId" node coming in response

router.calculateRoute(
    {
        ...
        "requestId": "Route_1"
    },
    CallBackFn,
    function (error) {
      alert(error.message);
    }
);

Trying to set as below in Version V8:

_platform = new H.service.Platform({
      apikey: _appkey,
    });
router = _platform.getRoutingService(null, 8);
router.i = {"X-Request-ID": "Route_1"}

From the above code, able to set request header. But not able to read from response header from callback function

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

锦爱 2025-02-08 19:40:18

路由v7:requestId
路由V8:使用标题X-Request-ID

X-Request-ID

您可以使用非标准HTTP HETER X-REQUEST-ID使用请求标识符标记请求。该服务将使该值转发到响应,无论是成功还是失败。如果没有提供值,则将在传入请求上生成一个UUID,并且该值将作为X-Request-ID附加到响应中。虽然您可以使用任何字符串作为请求标识符,但我们建议使用UUID唯一地标识您的请求或请求组。

迁移指南: https://developer.here.here.here.com/documentation/documentation/routing/routing/routing -api/migration_guide/index.html

V8指南: https://developer.here.com/documentation/routing-api/dev_guide/topics/trace-request.html

routing v7: requestId
routing v8: Use the header X-Request-ID

X-Request-ID

You can tag your requests with a request identifier using the non-standard HTTP header X-Request-Id. The service will forward this value to the response, be it a success or a failure. If no value is provided, a UUID will be generated on the incoming request and this value will be attached to the response as the X-Request-Id. While you can use any string as the request identifier, we recommend using a UUID to uniquely identify your requests or group of requests.

migration guide : https://developer.here.com/documentation/routing-api/migration_guide/index.html

v8 guide : https://developer.here.com/documentation/routing-api/dev_guide/topics/trace-request.html

风流物 2025-02-08 19:40:18

两年后,我遇到了同样的问题。到目前为止,提供的答案还没有说明这是用于路由API的JavaScript助手的此处地图SDK,并且问题是响应标题没有可用。

我发现您可以使用出站标题:

 const router = platform.getRoutingService(
    {
      headers: {
        'X-Request-ID': 'foo',
      },
    },
    8
  );

但是到目前为止,还没有找到从响应中检索请求ID的支持方法(它在那里,因此它可以使用 - 只是无法通过代码获取)。我想我要么切换到使用此处的路由API Direct(使用GET或POST),要么找到另一种方法来跟踪我的请求。

Two years later and I've hit the same issue. The answer so far provided doesn't account for the fact this is the Here Maps SDK for Javascript helper for the Routing API, and the issue is the response headers aren't made available.

I have found you can pass the outbound header using:

 const router = platform.getRoutingService(
    {
      headers: {
        'X-Request-ID': 'foo',
      },
    },
    8
  );

but thus far, haven't found a supported way of retrieving the request ID from the response (it's there, so it's working - just can't get to it via code). I think I'll either switch to using the HERE Routing API direct (using GET or POST), or find another way around tracking my requests.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文