Reputation: 553
NSString *urlString = @"http://chkdin.com/dev/api/peoplearoundmexy/?";
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSString *parameterString=[NSString stringWithFormat:@"skey=%@&user_id=%@",@"XXXXXXX",@"3225"];
NSLog(@"%@",parameterString);
[request setHTTPMethod:@"POST"];
[request setURL:url];
[request setValue:parameterString forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
NSData *postData = [parameterString dataUsingEncoding:NSUTF8StringEncoding];
[request setHTTPBody:postData];
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error];
NSLog(@"%@",[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error]);
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSLog(@"%@",dict);
This is my json parsing, my problem is when I am hit this api it is showing
{
message = "Valid skey required.";
status = 0;
}
But this api is working in safari.i am think is the problem is for request adding to url wrong. can you help me please....
Upvotes: 2
Views: 115
Reputation: 1167
i tried following code without AFNetworking
and its working fine.
NSString *post = [NSString stringWithFormat:@"skey=%@&user_id=%@",@"sa6rw9er7twefc9a7dvcxcheckedin",@"3225"];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://chkdin.com/dev/api/peoplearoundmexy/?%@",post]]];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:nil];
NSError *error;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error];
NSLog(@"%@",[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error]);
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSLog(@"%@",dict);
Upvotes: 1
Reputation: 8322
i got response through AFNetworking 3
try this
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
[manager GET:@"http://chkdin.com/dev/api/peoplearoundmexy/?" parameters:@{@"skey":@"sa6rw9er7twefc9a7dvcxcheckedin",@"user_id":@"3225"} progress:nil success:^(NSURLSessionTask *task, id responseObject) {
NSLog(@"%@",responseObject);
} failure:^(NSURLSessionTask *operation, NSError *error) {
}];
Upvotes: 1