Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to send POST XML from iOS app?
    primarykey
    data
    text
    <p>So, I've ran over and over the web in search for anything about sending XML with POST from iPhone app - no luck so far, none!</p> <p>I'm using in my app KissXML, which I find very easy and useful when it comes to getting XML out of response - but quite opposite when sending XML to server... Here is my method for connecting and receiving XML. I tried to put NSString containing simply my XML request into body of POST request, but it doesn't work as planned.</p> <pre><code>-(void)prepareTransaction{ NSLog(@"FXSecondVC: preparing transaction..."); NSString *login = [[NSUserDefaults standardUserDefaults] stringForKey:@"kUsername"]; NSString *password = [[NSUserDefaults standardUserDefaults] stringForKey:@"kPassword"]; NSString *host = [[NSUserDefaults standardUserDefaults] stringForKey:@"kURLServer"]; NSURL *url = [[NSURL alloc] initWithString:host]; AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url]; [httpClient setAuthorizationHeaderWithUsername:login password:password]; [httpClient registerHTTPOperationClass:[AFKissXMLRequestOperation class]]; NSString *xmlString = @"&lt;RootEl xmlns=\"http://some.url/goes/here\"&gt;" "&lt;Element1&gt;12678967.543233&lt;/Element1&gt;" "&lt;Element2&gt;" "&lt;string xmlns=\"bla.bla/url\"&gt;" "String content&lt;/string&gt;" "&lt;string xmlns=\"bla.bla/url\"&gt;" "String content&lt;/string&gt;" "&lt;/Element2&gt;" "&lt;Element3&gt;true&lt;/Element3&gt;" "&lt;Element4&gt;String content&lt;/Element4&gt;" "&lt;Element5&gt;1999-05-31T11:20:00&lt;/Element5&gt;" "&lt;Element6&gt;true&lt;/Element6&gt;" "&lt;/RootEl&gt;"; NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST" path:kServerRequestURL parameters:nil]; [request setHTTPBody:[xmlString dataUsingEncoding:NSUTF8StringEncoding]]; AFKissXMLRequestOperation *operation = [AFKissXMLRequestOperation XMLDocumentRequestOperationWithRequest:request success:^(NSURLRequest *req, NSHTTPURLResponse *resp, DDXMLDocument *XMLDocument){ NSLog(@"[SUCCESS]: XMLDocument: %@", XMLDocument); }failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, DDXMLDocument *XMLDocument) { NSLog(@"error parsing: %@", [error localizedDescription]); }]; [operation start]; } </code></pre> <p>This is what I'm getting in <code>response</code>:</p> <pre><code>2012-11-21 19:40:09.884 FXApp[19662:707] FXSecondVC: preparing transaction... 2012-11-21 19:40:10.011 FXApp[19662:707] error parsing: Expected status code in (200-299), got 400 </code></pre> <p>Am I missing something here? I want to use KissXML, because it the simplest way (at least known to me) to use already prepared XML document in successful response, but if solution requires changing framework - don't hesitate. The priority is to get it working. I hit dead end - this is driving me crazy, especially it is really urgent matter.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload