Download XML File with POST Method and Store it in Document's Directory
<p>I was successful on getting a reply from the server with my post method however, I have problem with downloading the xml file data.</p>

<p>Here is my Post method (that I've searched in stackoverflow)</p>

<pre><code>//We begin by creating our POST's body as an NSString, and converting it to NSData.
NSString *post = [NSString stringWithFormat:@"device_unique_key=%@&amp;provision_type=c", deviceUniqueKey];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

//Next up, we read the postData's length, so we can pass it along in the request.
NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[postData length]];

//Now that we have what we'd like to post, we can create an NSMutableURLRequest, and include our postData.
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:@"http://192.168.1.166/autoprovision/sip_setup/downloadSipSetup"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:postData];

//And finally, we can send our request, and read the reply by creating a new NSURLSession:
NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
[[session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
    NSString *requestReply = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];

    xmlData = data; //This is the data that I try to donwload as xml file.

    NSLog(@"requestReply: %@", requestReply);
}] resume];
</code></pre>

<p>I have <code>xmlData = data</code> //from the dataTaskRequest</p>

<p>Then here is my code for saving the xmlData to the Document's Directory</p>

<pre><code>// Display the network activity indicator
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];

// Perform the request on a new thread so we don't block the UI
dispatch_queue_t downloadQueue = dispatch_queue_create("Download queue", NULL);
dispatch_async(downloadQueue, ^{

    NSError* err = nil;
    NSHTTPURLResponse* rsp = nil;

    // Perform the request synchronously on this thread
    NSData *rspData = [NSURLConnection sendSynchronousRequest:request returningResponse:&amp;rsp error:&amp;err];

    // Once a response is received, handle it on the main thread in case we do any UI updates
    dispatch_async(dispatch_get_main_queue(), ^{
        // Hide the network activity indicator
        [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];

        if (rspData == nil || (err != nil &amp;&amp; [err code] != noErr)) {
            // If there was a no data received, or an error...

        } else {

            // Cache the file in the cache directory
            NSArray* paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
            path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"init.xml"];

            [[NSFileManager defaultManager] removeItemAtPath:path error:nil];
            [xmlData writeToFile:path atomically:YES];
            // Do whatever else you want with the data...

             [self loadDataFromXML];
        }
    });

});
</code></pre>

<p>The problem is that the xmlData is not working when I parse it using NSXMLParser. I tried to use an xml file and put it inside my project and it parses the xml but the xmlData that I downloaded doesn't get parsed (parse delegates are not called). I think my way of downloading the file is wrong. Can someone help me?</p>