0

I am developing one app,in that i have used to send my contact numbers to the server through WebServices.Here i get the my contact numbers an array,and i send the contact array through webservices.Here below code,

NSString *myRequestString1 = [[NSString alloc] initWithFormat:@"contact_numbers=%@",MobiileArray ];


NSData *myRequestData = [ NSData dataWithBytes: [ myRequestString1 UTF8String ] length: [ myRequestString1 length ] ];
NSMutableURLRequest *request = [ [ NSMutableURLRequest alloc ] initWithURL: [ NSURL URLWithString:@"http://myproject.in/myproject-contacts.php"]];

[request setHTTPMethod: @"POST"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
[request setHTTPBody: myRequestData];
NSURLResponse *response;
NSError *err;
NSData *returnData = [NSURLConnection sendSynchronousRequest: request returningResponse:&response error:&err];
NSError* error;
NSMutableArray* result = [NSJSONSerialization JSONObjectWithData:returnData
                                                         options:kNilOptions

                                                           error:&error];
NSLog(@"result: %@", result);

but the response is null ,any mistakes on my code? can you please suggest me Thank you.

Alex Andrews
  • 1,498
  • 2
  • 19
  • 33
G.P.Reddy
  • 556
  • 3
  • 20

1 Answers1

0

Try below solution..!

Replace this lines of code

NSString *myRequestString1 = [[NSString alloc] initWithFormat:@"contact_numbers=%@",MobiileArray ];
NSData *myRequestData = [ NSData dataWithBytes: [ myRequestString1 UTF8String ] length: [ myRequestString1 length ] ];

//With this lines of code

//NSDictionary *dict = [NSDictionary dictionaryWithObject: MobiileArray forKey:@"contact_numbers"];

NSString* myRequestString1 = [MobiileArray JSONRepresentation];
NSData *myRequestData = [myRequestString1 dataUsingEncoding:NSUTF8StringEncoding];

//put

[request setValue:@"application/json" forHTTPHeaderField:@"content-type"];

Check it...

Vidhyanand
  • 5,369
  • 4
  • 26
  • 59