dshu1235 2013-08-01 17:08
浏览 33

在iOS中检索部分响应,将POST请求发送到发送另一个POST请求的PHP表单

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!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
    • ¥15 个人网站被恶意大量访问,怎么办
    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 Centos / PETGEM
    • ¥15 划分vlan后不通了
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)