国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

數據請求

2019-11-14 18:09:34
字體:
來源:轉載
供稿:網友

1.Get請求

//get把傳輸的數據 放在鏈接地址里面- (void)getRequest{    NSString *interfaceString = @"http://apis.baidu.com/showapi_open_bus/mobile/find";    NSString *requestContentString = @"num=15761672938";        NSString *urlString = [NSString stringWithFormat:@"%@?%@",interfaceString,requestContentString];    NSURL *url = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];//    可變請求 可以添加請求方式 以及請求的 請求頭 或者更多//    timeoutInterval請求所需時間 超過所需時間 超過時間不再發送這個請求//    cachePolicy緩存內容的方式    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUsePRotocolCachePolicy timeoutInterval:10];    NSString *apiKey = @"e7f5ac9e7c42a6c8cb125ee1d7e8779e";//    把apiKey 發送給服務器 指定的請求 位置//    forHTTPHeaderField需要的Key 是服務器指定的key    [request addValue:apiKey forHTTPHeaderField:@"apiKey"];        //    指定http的請求方式    request.HTTPMethod = @"GET";//一般都是大寫    [NSURLConnection sendAsynchronousRequest:request queue:[[NSOperationQueue alloc]init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {        NSLog(@"%@",response);        //    解析json文件        //    把data轉換成json文件        NSDictionary *info = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];        NSLog(@"%@",info);        NSLog(@"info===%@   ,%@%@",info[@"showapi_res_body"][@"name"],info[@"showapi_res_body"][@"prov"],info[@"showapi_res_body"][@"city"]);    }];}

2.Post請求

//post- (void)postRequest{    NSURL *url = [NSURL URLWithString:@"http://www.weihuok.com/customer2/GetService"];//    請求參數//    PlatformType設備類型 3表示ios設備    NSDictionary *dic = @{@"PlatformType":@"3"};    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10];//    設置請求方式    request.HTTPMethod = @"POST";//    設置 請求的參數//    HTTPBody要的是data//    dataUsingEncoding把字符串轉成data    request.HTTPBody = [[NSString stringWithFormat:@"%@",dic]dataUsingEncoding:NSUTF8StringEncoding];    [NSURLConnection sendAsynchronousRequest:request queue:[[NSOperationQueue alloc]init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {        NSDictionary *info = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];        NSLog(@"==%@",info);    }];    }

 3.HTTP  Get請求

 GET URL 字符串地址 parameters boby體的內容

    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

    [manager GET:@"" parameters:nil success:^(AFHTTPRequestOperation *operation, id responSEObject) {

//        responseObject請求下來的數據內容

        

    } failure:^(AFHTTPRequestOperation *operation, NSError * error) {

        

    }];

4.HTTP Post請求

 //post    parameters需要post的內容

    [manager POST:@"" parameters:@{} success:^(AFHTTPRequestOperation * operation, id responseObject) {

        

    } failure:^(AFHTTPRequestOperation * operation, NSError * error) {

        

    }];

  


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 临沂市| 海盐县| 拜泉县| 汨罗市| 肇庆市| 连江县| 保亭| 庆云县| 富川| 和田市| 遵义市| 金昌市| 长垣县| 绍兴市| 团风县| 虎林市| 盐亭县| 库尔勒市| 封丘县| 新泰市| 安龙县| 上林县| 仁怀市| 肇庆市| 乡城县| 永顺县| 彭山县| 寻甸| 赤壁市| 嫩江县| 福海县| 勐海县| 根河市| 攀枝花市| 汾西县| 宜都市| 乃东县| 台南市| 新乡市| 滦南县| 平湖市|