Hi, fairly new to the world of iOS development so please bare with me.
I want to send a request message to a web service that I created in PHP. It will take the XML request, process and then provide a response XML message.
However, the issue I'm having is that when sending data to the Web Service it is in NSData form.
NSLog of the data being sent is:
However the PHP script is expecting an XML message like this:
So my question is, is there a way of sending the XML without converting to data, or is there a way to convert the NSData string to readable XML on the PHP Server Side?
I have the PHP script to currently output what is being passed in using the following code, but the NSLog of the response data in connectionDidFinish method is not printing anything to the console. So I'm not sure if the PHP file is even getting the POST message.
The code to send the data is as follows:
Any help would be greatly appriciated
Thanks in advance.
I want to send a request message to a web service that I created in PHP. It will take the XML request, process and then provide a response XML message.
However, the issue I'm having is that when sending data to the Web Service it is in NSData form.
NSLog of the data being sent is:
Code:
<3c3f786d 6c207665 7273696f etc etc ... 743e>
However the PHP script is expecting an XML message like this:
Code:
<?xml version="1.0" ?>
<request>
<tag-1></tag-1>
<tag-2></tag-2>
</request>
So my question is, is there a way of sending the XML without converting to data, or is there a way to convert the NSData string to readable XML on the PHP Server Side?
I have the PHP script to currently output what is being passed in using the following code, but the NSLog of the response data in connectionDidFinish method is not printing anything to the console. So I'm not sure if the PHP file is even getting the POST message.
Code:
$rawPostXML = file_get_contents("php://input");
echo $rawPostXML;
The code to send the data is as follows:
Code:
// Construct the webservice URL
NSURL *url = [NSURL URLWithString:@"http://localhost/web/check_data.php"];
NSString *requestXML = @"<?xml version='1.0'?><request><tag-1>VALUE1</tag-1><tag-2>VALUE2</tag-2></request>";
NSData *data = [requestXML dataUsingEncoding:NSUTF8StringEncoding];
// Create a request object with that URL
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30];
[request setHTTPBody:data];
[request setHTTPMethod:@"POST"];
// Instantiate the object to hold all incoming data
[responseXMLData release];
responseXMLData = [[NSMutableData alloc] init];
// Create and initiate the connection - non-blocking
connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
Any help would be greatly appriciated
Thanks in advance.