0
NSURL *URL = [NSURL     URLWithString:@"http://"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
request.HTTPMethod = @"POST";

NSString *params = @"json=deepak";
NSData *data = [params dataUsingEncoding:NSUTF8StringEncoding];


[request addValue:@"8bit" forHTTPHeaderField:@"Content-Transfer-Encoding"];
[request addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request addValue:[NSString stringWithFormat:@"%i", [data length]] forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:data];


NSURLResponse *responce;
NSError *error;
NSData *returnData = [ NSURLConnection sendSynchronousRequest:request returningResponse:&responce error:&error];
NSString *content = [NSString stringWithUTF8String:[returnData bytes]];
NSLog(@"responseData: %@", content);

Hi everyone, I am using code from stackOverflow itself and the answer written is working, But i am getting

"response data= null" from php server

my simple server code is

$json = CJSON::decode($_POST['json'],TRUE); echo CJSON::encode($json);

Deepak
  • 177
  • 2
  • 11
  • Is `returnData` null also? (If so, what does `error` contain?) – Phillip Mills Oct 15 '12 at 13:32
  • Thank for the reply.. There is no response in returnData also.. I am just echoing at server side after decoding the data.. – Deepak Oct 16 '12 at 05:51
  • have you checked that decode/encode on server is actually working? – pre Oct 16 '12 at 06:58
  • Yes its working great for android app only problem is not working for my iphone app... – Deepak Oct 16 '12 at 07:06
  • Even i tried not sending json key rather sending thing other then it gave me error in response saying that object not found at json something like this.....plz help me out guys its very necessary for my work...thank u – Deepak Oct 16 '12 at 07:12
  • PLZ some buddy help me out....at server side if i do not use decode its working perfectly fine...plz reply back what is going wrong in my code ...Thank u – Deepak Oct 17 '12 at 05:47

1 Answers1

0

Yes finally i got my problem solved..... To make key pair value i have to send data in form of array manner. i.e

 @"{\"user\":\"deepak\",\"password\":\"1234\"}";

this is value for json key.

then u can decode at php server using

$json = CJSON::decode($_POST['json'],TRUE); echo CJSON::encode($json);

JUST LIKE THIS and it works like charm

Deepak
  • 177
  • 2
  • 11