带有XML主体的AFNetworking 2.x POST请求 [英] AFNetworking 2.x POST request with xml body
本文介绍了带有XML主体的AFNetworking 2.x POST请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将某些数据以XML格式发布到服务器。
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主体xml内容看起来很脏。像这样:
POST body xml content looks smth. like that:
<action name='job'>jobName</action>
HttpClientXML具有以下定义:
HttpClientXML has this definitions:
self.responseSerializer = [AFXMLParserResponseSerializer serializer];
self.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/xml"];
在版本1.x中,这可以通过 AFXMLRequestOperation $ c $来实现c>。但是在2.x版本中,我无法使用
AFHTTPSessionManager
获得有效的解决方案。
In version 1.x this was doable with AFXMLRequestOperation
. But in version 2.x I can not get the working solution with AFHTTPSessionManager
.
有什么建议吗?
推荐答案
这是解决方案...
request.HTTPBody = [self.body dataUsingEncoding:NSUTF8StringEncoding];
request.HTTPMethod = @"POST";
[request setValue:@"text/xml" forHTTPHeaderField:@"Content-Type"];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
这篇关于带有XML主体的AFNetworking 2.x POST请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文