I’m trying to retrieve data from a POST method, code as follows:
-(void)postXMLFeed:(NSString *)XMLStrPost
{
//NSLog (@"XML Feed3: ", XMLStrPost);
NSURL *url = [NSURL URLWithString:@"http://xxx.xxx.x.xxx/stephen/sync_upload.php"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setValue:@"text/xml" forHTTPHeaderField:@"Content-type"];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[XMLStrPost dataUsingEncoding:NSASCIIStringEncoding]];
NSURLResponse *response;
NSError *error;
response = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
// Update log file.
NSLog(@"XML feed POSTED to website.");
//[super postXMLFeed];
}
My XML feed is stored in the variable XMLStrPost. The above code seems to work but I have no way of confirming it.
The script should unparse the string and write it to a database, but this does not seem to be happening. Before the unparse takes place I want to confirm that script is being called.
How can I confirm that sync_upload.php script is called?
You’re misusing the API.
+[NSURLConnection sendSynchronousRequest:returningResponse:error]returns anNSDataobject, which is the body of the response. You’re assigning it into anNSURLResponseobject, which means you’re not only breaking the type system (you should be getting a warning when compiling), but you’re also losing the pointer to theNSURLResponsethat the connection gave you.It’s like you’re shooting yourself twice in the foot with one bullet… (“Shooting two feet with one bullet”?)