欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

.netcore 写快递100的快递物流信息查询接口的实现

程序员文章站 2022-04-22 23:25:20
快递100的物流信息查询接口,官方提供了一些demo;还好官方提供的代码是.netcore版本写的,不过写的有点low;根据官方提供的代码,我按照.netcore 的风格重构了代码;核心代码如下:上面...

快递100的物流信息查询接口,官方提供了一些demo;还好官方提供的代码是.netcore版本写的,不过写的有点low;根据官方提供的代码,我按照.netcore 的风格重构了代码;核心代码如下:

上面的代码一眼看,就知道必须要使用依赖注入;我们看到 在构造函数里使用了httpclient _client    这个东西;(因为要调用快递100的接口),

我们在startup里接着写:

如上代码应该是最常用的注册方法;结果报错,错误信息如下:

system.aggregateexception:“some services are not able to be constructed (error while validating the service descriptor 'servicetype: muxue.wetao.mall.core.kuaidi100.kuaidi100helper lifetime: scoped implementationtype: muxue.wetao.mall.core.kuaidi100.kuaidi100helper': unable to resolve service for type 'system.net.http.httpclient' while attempting to activate 'muxue.wetao.mall.core.kuaidi100.kuaidi100helper'.)”
 
 
invalidoperationexception: unable to resolve service for type 'system.net.http.httpclient' while attempting to activate 'muxue.wetao.mall.core.kuaidi100.kuaidi100helper'.

根据错误信息看,应该是httpclient出了问题了;找了很久才找到解决方法,修改startup里的注册方法

这样就没问题了。

到此这篇关于.netcore 写快递100的快递物流信息查询接口的实现的文章就介绍到这了,更多相关.netcore 快递查询接口内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!