Question

I am trying to POST some data to the server with body formatted as XML.

[[HttpClientXML sharedClientWithBaseUrl:self.baseUrl] POST:@"/postXml/" parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
    BSLog(@"Success");
} failure:^(NSURLSessionDataTask *task, NSError *error) {
    BSLog(@"Error: %@",error.localizedDescription);
}];

POST body xml content looks smth. like that:

<action name='job'>jobName</action>

HttpClientXML has this definitions:

self.responseSerializer = [AFXMLParserResponseSerializer serializer];
self.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/xml"];

In version 1.x this was doable with AFXMLRequestOperation. But in version 2.x I can not get the working solution with AFHTTPSessionManager.

Any suggestions?

Was it helpful?

Solution

Here is the solution...

request.HTTPBody = [self.body dataUsingEncoding:NSUTF8StringEncoding];
request.HTTPMethod = @"POST";
[request setValue:@"text/xml" forHTTPHeaderField:@"Content-Type"];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top