Geeting Error in Using the x-www-form-urlencoded POST Request in ios

i used to request as post i getting some Error i didn’t get Correct response.Below is my Request:

NSURL *url = [[NSURL alloc] initWithString:@"xxxxxxx My URL xxxxxxxxxx"];

 NSString *myReqString=[NSString stringWithFormat:@"key=%@&email=%@&password=%@",@"1234",@"",@"123"];
 NSMutableURLRequest *request=[[NSMutableURLRequest alloc]init];
 NSData *postData = [myReqString dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
 [request setURL:url];
 [request setHTTPMethod:@"POST"];
 NSString *conLength=[NSString stringWithFormat:@"%d",postData.length];
 [request setValue:conLength forHTTPHeaderField:@"Content-Length"];
 [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
 [request setHTTPBody:postData];

this is my Response:

[NSURLConnection sendAsynchronousRequest:request queue:[[NSOperationQueue alloc]init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
            if([data length]>0 && connectionError==nil){
                NSError *error;

                NSString *strr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
                NSLog(@"data is: %@",strr);
 NSMutableDictionary *jsonResponse=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];



My outPut is :

data is: array(0) {

How to Solve this Error or Can i Set the Content Type For Response To Fix it.

Source: json

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.