ios afneworking2.x 使用方法

//獲取地址
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    NSMutableSet *acceptableSet = [NSMutableSet setWithSet:manager.responseSerializer.acceptableContentTypes];
    [acceptableSet addObject:@"text/html"];
    //否則會報錯AFNetworking:error:Request failed: unacceptable content-type: text/html
    manager.responseSerializer.acceptableContentTypes = acceptableSet;
    
    NSString * imageURLStr=@"http://www.d-shang.com/index.php?blog/getadv";
    NSURL * imageURL=[NSURL URLWithString:imageURLStr];
    NSDictionary *dict = @{@"format": @"json"};

    [manager GET:imageURLStr parameters:dict success:^(AFHTTPRequestOperation * _Nonnull operation, id  _Nonnull responseObject) {
        NSLog(@"%@",responseObject);
        
    } failure:^(AFHTTPRequestOperation * _Nullable operation, NSError * _Nonnull error) {
        NSLog(@"失敗%@",error);
    }];
相關文章
相關標籤/搜索