环境依赖
使用示例
获取当前系统时间
ITopClient client = new DefaultTopClient("http://gw.api.taobao.com/router/rest", "appkey", "appsecret", "json");
TimeGetRequest req = new TimeGetRequest();
TimeGetResponse rsp = client.Execute(req);
Console.WriteLine(rsp.Body);
获取线上发货物流订单信息
String url = new String("http://gw.api.taobao.com/router/rest");
ITopClient client = new DefaultTopClient(url, appkey, secret);
AliexpressLogisticsRedefiningGetonlinelogisticsinfoRequest req = new AliexpressLogisticsRedefiningGetonlinelogisticsinfoRequest();
req.ChinaLogisticsId = "LA234234CN";
req.InternationalLogisticsId = "LP00038357949881";
req.LogisticsStatus = "CLOSED";
req.GmtCreateEndStr = "2016-06-27 18:15:00";
req.PageSize = 10L;
req.QueryExpressOrder = false;
req.CurrentPage = 1L;
req.OrderId = 60015640573917L;
req.GmtCreateStartStr = "2016-06-27 18:20:00";
AliexpressLogisticsRedefiningGetonlinelogisticsinfoResponse rsp = client.Execute(req, sessionKey);
Console.WriteLine(rsp.Body);
服务地址
API服务地址
环境 |
HTTP请求地址 |
HTTPS请求地址 |
正式环境 |
||
海外正式环境 |
高级功能
不解释响应字符串为对象(这时候XxxResponse包含的对象为null)
DefaultTopClient.SetDisableParser(true)
采用精简化的JSON结构返回,去除多余JSON节点
DefaultTopClient.SetUseSimplifyJson(true)
取消API调用日志打点
DefaultTopClient.SetDisableTrace(true)
忽略HTTPS证书检查(建议只在测试环境打开)
DefaultTopClient.SetIgnoreSSLCheck(true)
取消响应GZIP压缩功能(GZIP压缩功能可以显著的减少网络传输,强烈建议不要取消)
DefaultTopClient.SetUseGzipEncoding(false)
设置HTTP连接超时和读超时时间(网络环境差的情况下可以适当增大)
// HTTP等待请求开始返回的超时时间:默认20秒
DefaultTopClient.SetTimeout(20000L)
// HTTP等待读取数据完成的超时时间:默认60秒
DefaultTopClient.SetReadWriteTimeout(60000L)
修改日志打点存储路径
DefaultTopLogger.FilePath = "c:/tmp/topsdk.log";
API调用出错自动重试(一般情况下ISP类的错误是可以重试成功的)
AutoRetryTopClient client = new AutoRetryTopClient("http://gw.api.taobao.com/router/rest", "appkey", "appsecret", "json");
client.SetMaxRetryCount(3);
client.SetRetryWaitTime(100L);
TimeGetRequest request = new TimeGetRequest();
TimeGetResponse response = client.Execute(request);
if (!response.IsError) {
Console.WriteLine(response.Body);
}
API调用就近路由(根据API发起调用所在地选择就近的TOP机房进行调用)
ClusterTopClient client = new ClusterTopClient("http://gw.api.taobao.com/router/rest", "appkey", "appsecret", "json");
TimeGetRequest request = new TimeGetRequest();
TimeGetResponse response = client.Execute(request);
Console.WriteLine(response.Body);
注意事项