Client side code. Message was base64 encoded before being sent to this function.
Code:
- (void)sendSerializedGreeting:(NSString *)message
{
// Show a loading indicator
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
NSString *greetingURL = [NSString stringWithFormat:@"http://yourwebsite.com", [[UIDevice currentDevice] uniqueIdentifier]];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:greetingURL]
cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
NSDictionary *headerFieldsDict = [NSDictionary dictionaryWithObjectsAndKeys:@"text/xml; charset=utf-8", @"Content-Type", nil];
[theRequest setHTTPBody:[message dataUsingEncoding:NSUTF8StringEncoding]];
[theRequest setAllHTTPHeaderFields:headerFieldsDict];
[theRequest setHTTPMethod:@"POST"];
// create the connection with the request and start loading the data
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection == nil)
{
NSLog(@"Failed to create the connection");
}
}
Server side code:
// PHP
Code:
$file = base64_decode(file_get_contents("php://input"));
// ASP
Code:
StreamReader sr = new StreamReader(Page.Request.InputStream);
string file = Encoding.ASCII.GetString(Convert.FromBase64String(sr.ReadToEnd()));