文档中心 > Dropshipping(已废弃)

Java SDK Tutorials

更新时间:2020/01/10 访问次数:11116

Environmental Dependency

Usage Example

Obtain the current system time:

DefaultTaobaoClient client = new DefaultTaobaoClient("http://gw.api.taobao.com/router/rest", "appkey", "appsecret");
TimeGetRequest request = new TimeGetRequest();
TimeGetResponse response = client.execute(request);
if (response.isSuccess()) {
         System.out.println(response.getBody());
}

Obtain the online logistics information:

String url = new String("http://gw.api.taobao.com/router/rest");
TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret);
AliexpressLogisticsRedefiningListlogisticsserviceRequest req = new AliexpressLogisticsRedefiningListlogisticsserviceRequest();
AliexpressLogisticsRedefiningListlogisticsserviceResponse rsp = client.execute(req, sessionKey);
System.out.println(rsp.getBody());

Service URL

The following table lists API service URLs.

Environment HTTP Request URL HTTPS Request URL
Formal environment http://gw.api.taobao.com/router/rest https://eco.taobao.com/router/rest
Overseas formal environment http://api.taobao.com/router/rest https://api.taobao.com/router/rest

Advanced Features

  • Disable the interpretation of response character strings (where the object of XxxResponse is null):
DefaultTaobaoClient.setNeedEnableParser(false);
  • Use the simplified JSON return format and remove redundant JSON nodes:
DefaultTaobaoClient.setUseSimplifyJson(true);
  • Disable API invocation logging:
DefaultTaobaoClient.setNeedEnableLogger(false);
  • Ignore the HTTPS certificate check (It is recommended to enable this only in the test environment.):
DefaultTaobaoClient.setIgnoreSSLCheck(true);
  • Disable GZIP compression for the response (It is strongly recommended that developers do not disable GZIP compression as it can significantly reduce network transmission.):
DefaultTaobaoClient.setUseGzipEncoding(false);
  • Set HTTP connection and read timeout intervals (Increase such timeout intervals appropriately under poor network conditions.):
//Default timeout interval for an HTTP connection: 3s
//Default timeout interval for an HTTP read response: 15s
DefaultTaobaoClient client = new DefaultTaobaoClient("http://gw.api.taobao.com/router/rest", "appkey", "appsecret", connectTimeout, readTimeout)
  • Enable an automatic retry for API invocation errors (Generally, a retry can be successful for ISP errors.):
AutoRetryTaobaoClient client = new AutoRetryTaobaoClient("http://gw.api.taobao.com/router/rest", "appkey", "appsecret");
client.setMaxRetryCount(3);
client.setRetryWaitTime(100L);
TimeGetRequest request = new TimeGetRequest();
TimeGetResponse response = client.execute(request);
if (response.isSuccess()) {
         System.out.println(response.getBody());
}
  • Set shortest-path routing for API invocation (that is, invoke an API from the TOP equipment room nearest to the location where a request for API invocation is initiated):
ClusterTaobaoClient client = new ClusterTaobaoClient("http://gw.api.taobao.com/router/rest", "appkey", "appsecret");
TimeGetRequest request = new TimeGetRequest();
TimeGetResponse response = client.execute(request);
System.out.println(response.getBody());

Important Notes

  • As the implementation class of TaobaoClient is thread-safe, there is no need to create a new TaobaoClient implementation class for each request for API invocation.
  • When an instance of the TaobaoClient implementation class is created, format is set to json. Compared to the XML format, the JSON format can reduce the volume of data transmission and improve the efficiency of requests for API invocation.

FAQ

关于此文档暂时还没有FAQ
返回
顶部