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);

6
  • Is returnData null also? (If so, what does error contain?) Oct 15, 2012 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, 2012 at 5:51
  • have you checked that decode/encode on server is actually working?
    – pre
    Oct 16, 2012 at 6:58
  • Yes its working great for android app only problem is not working for my iphone app...
    – Deepak
    Oct 16, 2012 at 7: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, 2012 at 7:12

1 Answer 1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.