首页 > 解决方案 > C# .NET 实现 DHL API 跟踪

问题描述

我尝试将服务引用添加到我的项目中,但这不起作用?

https://api-eu.dhl.com/tracking

尝试添加服务参考时出现以下错误

Metadata contains a reference that cannot be resolved: 'https://api-eu.dhl.com/tracking'.
The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was ''.
The remote server returned an error: (401) Unauthorized.
If the service is defined in the current solution, try building the solution and adding the service reference again.

标签: c#.netrestapi

解决方案


您收到该错误是因为您传递了错误的密钥,并且通过阅读评论我看到您还没有注册应用程序。

使用 DHL API 端点需要以下标头。

'Accept': 'application/json',
'DHL-API-Key': 'ApiKeyHere'

Python中有一个书面示例https://developer.dhl.com/api-reference/shipment-tracking#get-started-section%example-requests-to-the-api

如果您在用 C# 编写它时需要帮助,您可以按照这个答案https://stackoverflow.com/a/39670617/5394806


推荐阅读