I have tried every possible method to send data in post method using NSURLSession,AFNetworking,NSURLConnection;but every time my backend developer says they are not receiving any data,although my co android developer is successfully sending data in POST.I am totally helpless now.Please help.
---- Using NSURLConnection ----
NSString *post = [NSString stringWithFormat:@"user_id=%@&email=%@",[[NSUserDefaults standardUserDefaults] valueForKey:@"UserId"],emailString];
NSLog(@"------%@-------",post);
NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding ];//[post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%lu",(unsigned long)[postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@app_user_service/app_invite_email",App_Domain_Url]]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if(conn) {
NSLog(@"Connection Successful");
} else {
NSLog(@"Connection could not be made");
}
// ---- Using AFNetworking ----
NSDictionary *dic2 = @{@"user_id": [[NSUserDefaults standardUserDefaults] valueForKey:@"UserId"] , @"email" : emailString};
AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc]initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
[manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[manager POST:urlstring parameters:dic2 progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSLog(@"success!");
NSDictionary *dict=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingAllowFragments error:nil];
NSLog(@"Response----> %@",dict);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"error: %@", error);
}];