iOS WebService SOAP 请求的实现
2017-10-10 10:44
369 查看
SOAP是简单对象访问协议是交换数据的一种协议规范,是一种轻量的、简单的、基于XML(标准通用标记语言下的一个子集)的协议,它被设计成在WEB上交换结构化的和固化的信息。
由于SOAP是基于XML的我们在传输过程中请求参数和返回内容都是XML格式,在这里我使用了XMLDictionary 转换工具
导入XMLDictionary
使用cocoapods导入 pod 'XMLDictionary'
github连接:https://github.com/nicklockwood/XMLDictionary
AFN实现SOAP
由于SOAP是基于XML的我们在传输过程中请求参数和返回内容都是XML格式,在这里我使用了XMLDictionary 转换工具
导入XMLDictionary
使用cocoapods导入 pod 'XMLDictionary'
github连接:https://github.com/nicklockwood/XMLDictionary
AFN实现SOAP
//我使用的该类是继承于AFHTTPSessionManager的 //ps 在soapStr中自己要设置命名空间 /** Post方式请求 @param methodString 方法名 @param parameter 参数 @param successBlock 成功回调 @param isShowHud 是否显示ProgressHUD */ - (void)httpPostRequestWithMethodString:(NSString *)methodString withParameters:(NSDictionary *)parameter success:(SuccessBlock)successBlock failure:(FailureBlock)failureBlock isShowHUD:(BOOL)isShowHud { if (isShowHud) { [MBProgressHUD showMessage:@"正在加载"]; } NSString *soapStr = [NSString stringWithFormat:@"<v:Envelope xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:d=\"http://www.w3.org/2001/XMLSchema\" xmlns:c=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:v=\"http://schemas.xmlsoap.org/soap/envelope/\"> <v:Header /> <v:Body xmlns=\"命名空间这个自己问后台要\" id=\"o0\" c:root=\"1\"> %@ </v:Body> </v:Envelope>",[@{methodString:parameter} XMLString]]; //请求头根据后台需要设置 [self.requestSerializer setValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; //在该处设置请求的SOAP请求内容 [self.requestSerializer setQueryStringSerializationWithBlock:^NSString * _Nonnull(NSURLRequest * _Nonnull request, id _Nonnull parameters, NSError * _Nullable __autoreleasing * _Nullable error) { return soapStr; }]; [self POST:@"调用地址问后台要" parameters:soapStr progress:^(NSProgress * _Nonnull uploadProgress) { } success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { [MBProgressHUD hideHUD]; NSString *result = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]; // NSLog(@"result:%@",result); successBlock([NSDictionary dictionaryWithXMLString:result]); } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { [MBProgressHUD showError:error.localizedDescription]; failureBlock(error); }]; }
相关文章推荐
- IOS 使用Http模拟SOAP请求Webservice时内容Unicode编码的实现
- iOS - AFNetworking3.0 发送SOAP请求到Webservice
- IOS:SOAP(Webservice)请求基于AFN2.6之后
- SOAP Webservice用AFNetworking实现请求
- iOS开发-进阶:SOAP web service用AFNetWorking实现请求
- iOS WebService Soap 请求遇到服务器400错误
- nusopa和soap 实现webservice
- 手把手教你做iOS的soap应用(webservice)
- iOS基于AFNetworking使用自签名证书实现HTTPS请求
- Android发送SOAP数据给服务器调用webservice,实现手机号归属地查询
- 使用Jquery Ajax的webservice请求来实现更简练的Ajax
- 使用GCD 信号量来实现iOS 同步网络请求
- iOS从webservice上请求数据,第一次接触怎么搞?
- 【soap】利用php的soap实现webservice
- 手把手教你做iOS的soap应用(webservice)
- 浅谈WebService SOAP、Restful、HTTP(post/get)请求
- iOS开发之结合asp.net webservice实现文件上传下载
- SOAP扩展PHP轻松实现WebService
- WebService(二)—JDK内置JAX-WS实现SOAP WebService
- 三种主流的WebService实现方案(REST/SOAP/XML-RPC)简述及比较