I have an iOS app that sends a POST request to a PHP form. I modified the PHP form to send another POST request (using cURL) to a third party API. The problem is that in iOS the returnString is the response from the cURL and I want to return just some part from the cURL response.
iOS code:
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
NSMutableData *body = [NSMutableData data];
//fill body
[request setHTTPBody:body];
//return and test
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(@"returnString = %@",returnString);
and in PHP I have this:
$post = '{"score":1337,"playerName":"Sean Plott","cheatMode":false}';
$theurl = "https://api.parse.com/1/classes/GameScore";
$ch = curl_init($theurl);
$headers = array(
'X-Parse-Application-Id: myAppID',
'X-Parse-REST-API-Key: myKey',
'Content-type: application/json',
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$response = curl_exec($ch);
$responseArray = json_decode($response, true);
echo $responseArray[0];
As you can see, I'm trying to only return to iOS the first element of the responseArray. However, I get the full response (even without the echo) of the cURL POST.
I know I can modify the iOS app to parse the full response and get the first element. However, I'm trying to not update the app just the back end method that used to return a single element with an echo statement.
Is this possible? How can I make PHP not return the full response of the cURL POST and just a part of it?
Thanks!