AFNetworking 3.0

 **Post server response

AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
       manager.requestSerializer = [AFHTTPRequestSerializer serializer];

     [manager.requestSerializer setValue:@"application/x-www-form-urlencoded;charset=utf-8" forHTTPHeaderField:@"Content-Type"];

**Your server sending data in  "text/html" **
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
**parameters
    NSDictionary *params = @{@"funcName": @"verifyLogin",
                             @"registeredEmail": @"mail",
                             @"registeredPassword":@"password"};
    [manager POST:@"http://example.com" parameters:params progress:nil success:^(NSURLSessionTask *task, id responseObject)
    {
        
        NSLog(@"JSON: %@", responseObject);
    } failure:^(NSURLSessionTask *operation, NSError *error)
    {
        NSLog(@"Error: %@", error);
    }];

    

** Get Server response

      NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];

    AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
    NSURL *URL =[NSURL URLWithString:@"https://rss.itunes.apple.com/api/v1/us/apple-music/hot-tracks/all/10/explicit.json"];
    NSURLRequest *request = [NSURLRequest requestWithURL:URL];
    
    NSURLSessionDataTask *dataTask = [manager dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error)
    {
        if (error)
        {
            NSLog(@"Error: %@", error);
        } else
        {
            NSLog(@"%@",response);
            NSLog(@"%@ ",  responseObject);
        }
    }];
    [dataTask resume];

**Network Rechability 

**status check 

 [[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        NSLog(@"Reachability: %@", AFStringFromNetworkReachabilityStatus(status));
    }];
    

    [[AFNetworkReachabilityManager sharedManager] startMonitoring];



**
if([[AFNetworkReachabilityManager sharedManager] isReachable])
     {
      NSLog(@"network is rechable");

     }
else
   {
          NSLog(@"network is not rechable");

   }






Previous
Next Post »