联系客服: iP138.com客服 iP138客服 |

Object-C(ios)调用快递查询接口示例:

                                    //
                                    //  ViewController.m
                                    //  ApiTest
                                    //
                                    //  Created by administrator on 16/9/8.
                                    //  Copyright © 2016年 star. All rights reserved.
                                    //

                                    #import "ViewController.h"

                                    #define Host @"https://api.ip138.com/express/info/"

                                    @interface ViewController ()<NSXMLParserDelegate>

                                    @end

                                    @implementation ViewController

                                    - (void)viewDidLoad {
                                        [super viewDidLoad];
                                        // Do any additional setup after loading the view, typically from a nib.
                                        NSString * token = @"859476648b3de65d7680494506dd1a1c6a";
                                        
                                        [self executeNetworkWithExpress:@"100613574827" token:token];
                                        
                                    }

                                    /**
                                     *示例https://api.ip138.com/express/info/?no=100613574827&token=859476648b3de65d7680494506dd1a1c6a
                                     *参数说明:
                                     *1. no string 快递单号
                                     *2. token string 购买服务后会提供
                                     */

                                    - (void)executeNetworkWithExpress:(NSString *)no  token:(NSString *)token{
                                       
                                        NSString * urlString =[NSString stringWithFormat:@"%@?no=%@&token=%@",Host,no,token];
                                        
                                        //准备网络请求
                                        NSString *newStr = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                                        NSURL *url = [NSURL URLWithString:newStr];
                                        NSURLRequest *requst = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:10];
                                        
                                        //请求异步链接
                                        [NSURLConnection sendAsynchronousRequest:requst queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
                                            
                                            if (connectionError) {
                                                NSLog(@"jsonError = %@",connectionError);
                                                return ;
                                            }

                                            NSError *jsonError = nil;
                                            NSString *jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
                                                
                                             NSDictionary *jsonResponse =
                                             [NSJSONSerialization JSONObjectWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding]
                                                                              options:0
                                                                                  error:&jsonError];
                                             if (jsonError) {
                                                  NSLog(@"jsonError = %@",jsonError);
                                                  return ;
                                             }
                                             NSLog(@"jsonResponse = %@",jsonResponse);
                                        }];
                                    }

                                    - (void)didReceiveMemoryWarning {
                                        [super didReceiveMemoryWarning];
                                        // Dispose of any resources that can be recreated.
                                    }

                                    @end