使用afnetworking和网络服务接口及soap发送并接收http/https请求:
来源:互联网 发布:cpa软件 编辑:程序博客网 时间:2024/05/01 21:42
使用afnetworking和网络服务接口及soap发送并接收http/https请求:
//1.创建请求体(格式和服务器端要求发送的一致,将参数替换成自己要传的参数,name,psw)
NSString *soapMessage = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><GetUserInfo xmlns=\"http://tempuri.org/\"><username>%@</username><pwd>%@</pwd></GetUserInfo></soap:Body></soap:Envelope>",name,psw];
//2.获取请求体的长度
NSString *soapLength = [NSString stringWithFormat:@"%ld",[soapMessage length]];
// AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc]initWithBaseURL:[NSURL URLWithString:@"http://tempuri.org"]];
//3.创建一个AFHTTPRequestOperationManager对象,设置属性
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
//3.1设置返回的格式为http(data数据)
manager.responseSerializer = [[AFHTTPResponseSerializer alloc]init];
//4.设置请求头信息
[manager.requestSerializer setValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[manager.requestSerializer setValue:soapLength forHTTPHeaderField:@"Content-Length"];
//创建一个nsurlrequest对象
NSMutableURLRequest *request = [manager.requestSerializer requestWithMethod:@"POST" URLString:@"http://192.168.0.10:8018/webservice/WebService.asmx" parameters:nil];
//设置request对象的请求体编码格式
[request setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
//创建一个队列
AFHTTPRequestOperation *operation = [manager HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {
//发送成功并接收到的数据信息—->responseObject
NSString *response = [[NSString alloc] initWithData:(NSData *)responseObject encoding:NSUTF8StringEncoding];
NSLog(@"%@, ------%@", operation, response);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSString *response = [[NSString alloc] initWithData:(NSData *)[operation responseObject] encoding:NSUTF8StringEncoding];
NSLog(@"%@, %@", response, error);
}];
[manager.operationQueue addOperation:operation];
- 使用afnetworking和网络服务接口及soap发送并接收http/https请求:
- howto使用http接收和发送简单的xml请求
- 使用SAAJ发送和接收SOAP消息
- 使用SAAJ发送和接收SOAP消息
- 使用URLConnction发送HTTP/HTTPS请求
- Qt 之 使用 https:// 发送 HTTP请求
- Qt 之 使用 https:// 发送 HTTP请求
- VPOS MAS-CNP接口——建立https连接发送请求并接收返回的XML数据流
- java发送HTTP和HTTPS请求
- java 发送http和https请求
- 使用MULE接收并处理HTTP请求
- 发送HTTP和HTTPS(单向验证)请求(包含POST请求)
- HttpURLConnection发送接收Http请求
- 使用Https发送请求
- ruby发送http,https请求
- JAVA发送http、https请求
- HttpClient 发送 HTTP、HTTPS 请求
- https和http协议接口post请求接口方法
- iOS 名称的国际化
- 【已解决】Android Studio无法识别虚拟机,虚拟机无法运行
- 在Ubuntu上下载、编译和安装Android最新内核源代码(Linux Kernel)
- 【HTTP】Fiddler(三)- Fiddler命令行和HTTP断点调试
- jquery获取元素值的方法(常见的表单元素)
- 使用afnetworking和网络服务接口及soap发送并接收http/https请求:
- 我不是《纪念碑谷》,我是玩法不一样的《Maestria》
- RTTI
- struts拦截器原理
- OpenCV Stitching 工程搭建
- 如何单独编译Android源代码中的模块
- 进程里杀死tomcat
- 一致性哈希算法学习笔记
- ie8的透明度&&透明度的兼容性写法