c# - 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.
解决方案
您收到该错误是因为您传递了错误的密钥,并且通过阅读评论我看到您还没有注册应用程序。
使用 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
推荐阅读
- database - 如何在 Visual Studio 的 C++/CLR 项目中使用数据库?
- python - 如何检查熊猫数据框中的列之间的冲突?
- python - 如何使用 PySpark 将分层 CSV 文件转换为 ADB 中的表
- python - 字典中numpy数组列的Python min/max
- android - 如何在没有背景噪音的情况下录制音频(心音)(例如:车辆声音、电视声音)
- kubernetes - 为什么 Kubernetes 中的 pod 会自动挂载服务帐户密钥?
- mysql - 如何一次从所有表中选择?
- sql - 两个元组之间的 SQL 索引,AND 条件
- reactjs - 尝试使用 redux-thunk,但它显示错误,即使对我来说一切都很好
- postgresql - 返回诗的总数,提到死亡的诗和提到爱的诗的平均字符数