AFNetworking升级到3.0以后,许多的接口都不能用了,原来使用soap发送到webservice的方式要换了,网上资料很少。
这是我的做法。
NSString *soapMessage =[NSString stringWithFormat:(soap字符串)];
NSString *soapLength = [NSString stringWithFormat:@"%lu", (unsigned long)[soapMessage length]];
//服务器地址
NSString *Url =[NSString stringWithFormat:(IP字符串)];
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.responseSerializer = [[AFHTTPResponseSerializer alloc] init];
manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes
setByAddingObject:@"text/xml"];
[manager.requestSerializer setValue:@"application/soap; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[manager.requestSerializer setValue:soapLength forHTTPHeaderField:@"Content-Length"];
//设置超时时间
[manager.requestSerializer willChangeValueForKey:@"timeoutInterval"];
manager.requestSerializer.timeoutInterval = 10.0f;
[manager.requestSerializer didChangeValueForKey:@"timeoutInterval"];
NSMutableURLRequest *request = [manager.requestSerializer requestWithMethod:@"POST" URLString:Url parameters:nil error:nil];
[request setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSURLSessionDataTask *task = [manager dataTaskWithRequest:request completionHandler:
^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
if(!error)
{
//成功的处理
}
else
{
//出错的处理
}
}];
[task resume];
});
http://write.blog.csdn.net/postedit/53217316 我CSDN的博客。