I am using NSURLConnection method to call the web services what I want is to replace it with 3rd party library AFNetworking how shall I achieve this I am calling the web Services with data first time here is what I am doing currently.
- (void)viewDidLoad {
[super viewDidLoad];
NSURL * linkUrl = [NSURL URLWithString:@URLBase];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:linkUrl];
NSString *msgLength = [NSString stringWithFormat:@"%lu", (unsigned long)[str length]];
[theRequest addValue: @"text/plain; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [str dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if( theConnection )
{
webData = [[NSMutableData alloc] init];
}
else
{
NSLog(@"theConnection is NULL");
}
}
#pragma mark -- Connection Delegate
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
//NSLog(@"%@",response);
//[webData setLength: 0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[webData appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(@"\nERROR with theConenction");
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSString *responseDataString = [[NSString alloc] initWithData:webData encoding:NSUTF8StringEncoding];
NSLog(@"Converted NSData %@ ",responseDataString);
}
here
[theRequest setHTTPBody: [str dataUsingEncoding:NSUTF8StringEncoding]];
str is my encrypted data like username and password. thanks in advance.!