开发者

How to obtain posted string from iPhone app on Server Side

开发者 https://www.devze.com 2023-03-03 03:18 出处:网络
I\'m new to Web Services for iPhone and have a quick question. I want to send some values up to my php script on the server, however since there are so many values I dont want to include them in the a

I'm new to Web Services for iPhone and have a quick question. I want to send some values up to my php script on the server, however since there are so many values I dont want to include them in the actual URL (access them in $_GET in PHP). I want to send up a XML string that will allow my PHP script to get all the data and process it. So far I have the following template for sending data:

NSURL *someURL = ...
NSString *xmlString = @"This would be the entire XML message";
NSData *data = [xmlString dataUsingEncoding:NSUTF8StringEncoding];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:someURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:90];

[req setHTTPBody:data];
[req setHTTPMethod:@"POST"];

Now my understanding is this would submit the XML to the PHP script. My question is how would I obtain this on 开发者_Go百科the server side ... what would the $_POST['?????'] value be?

Thanks


You can read:

$HTTP_RAW_POST_DATA

or do:

$rawPost = file_get_contents("php://input");

From the manual:

php://input allows you to read raw data from the request body. In case of POST requests, it preferrable to $HTTP_RAW_POST_DATA as it does not depend on special php.ini directives. Moreover, for those cases where $HTTP_RAW_POST_DATA is not populated by default, it is a potentially less memory intensive alternative to activating always_populate_raw_post_data. php://input is not available with enctype="multipart/form-data".

For more information, check out:

http://php.net/manual/en/wrappers.php.php

http://php.net/manual/en/reserved.variables.httprawpostdata.php


You can do print_r($_REQUEST) to see all GET/POST variables.

Since you're calling the page directly, I'd probably setup a quick script to log the data to a file when the page is called.

0

精彩评论

暂无评论...
验证码 换一张
取 消