-
快递查询
[C#]- https://www.6api.net/api/express/
- 阅读数:2435 上传时间:2020-11-21
- 示例代码
本代码示例是基于C#的六派数据接口进行数据请求 API服务请求的代码示例,使用前你需要:
①:通过https://www.6api.net/api/express/ 申请API服务
以下是完整代码示例:
class Response { public string statusCode; } static void Main(string[] args) { string method = "POST"; string url = "http://open.6api.net/express/search"; Dictionary<string, string> param = new Dictionary<string, string>(); param.Add("appkey", "yourappsecret"); param.Add("cpCode", "JD");//快递公司编码 例如圆通:YTO,详见:<a href='https://doc.liupai.net/web/#/21/242' target='_black'>快递公司编码对照表</a> param.Add("mailNo", "JDVF01604405153");//快递运单号 param.Add("tel", "参数3");//顺丰速运/丰网速运需传入收件人或寄件人手机号或手机号后四位(推荐使用寄件人) param.Add("orderType", "desc");//子节点时间排序 desc倒序 asc升序 param.Add("logisticsWarn", "0");//标记预警,默认值为0, 0:不标记,1:标记 Dictionary<string, string> headers = null; string result = api_send_request(method, url, param, headers); if (result == "") { //返回内容异常,发送请求失败 Console.WriteLine("发送请求失败"); return; } Response res = new JavaScriptSerializer().Deserialize<Response>(result); if (res.statusCode == "200") //有个别接口计费状态码为其他;请注意甄别 { //状态码为200, 说明请求成功 Console.WriteLine(string.Format("请求成功: {0}", result)); } else { //状态码非200, 说明请求失败 Console.WriteLine(string.Format("请求失败: {0}", result)); } Console.ReadLine(); }