IOS使用soap。
2015-12-07 17:21
453 查看
- (IBAction)DoSearch:(id)sender { NSString *soapMsg=@"<?xml version=\"1.0\" encoding=\"utf-8\"?>" "<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">" "<soap12:Body><getMobileCodeInfo xmlns=\"http://WebXml.com.cn/\"><mobileCode>123456789</mobileCode>" "<userID></userID></getMobileCodeInfo></soap12:Body></soap12:Envelope>"; NSURL *url=[NSURL URLWithString:@"http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx"]; NSMutableURLRequest *req=[NSMutableURLRequest requestWithURL:url]; NSString *soapMsg_Length=[NSString stringWithFormat:@"%d",soapMsg.length]; [req addValue:@"application/soap+xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; [req addValue:soapMsg_Length forHTTPHeaderField:@"Content-Length"]; [req setHTTPMethod:@"POST"]; [req setHTTPBody:[soapMsg dataUsingEncoding:NSUTF8StringEncoding]]; self.conn=[[NSURLConnection alloc]initWithRequest:req delegate:self]; if(self.conn) { self.webData=[NSMutableData data]; } } //报错的信息 - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error; { self.conn=nil; //self.webData=nil; } //开始获取 - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{ [self.webData setLength:0 ]; NSLog(@"开始了"); } //接收部分追回 - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{ [self.webData appendData:data]; NSLog([[NSString alloc]initWithBytes:data.bytes length:data.length encoding:NSUTF8StringEncoding]); } //完成后打出 - (void)connectionDidFinishLoading:(NSURLConnection *)connection{ NSString *thexml=[[NSString alloc]initWithBytes:[self.webData mutableBytes] length:[self.webData length] encoding:NSUTF8StringEncoding]; NSLog(thexml); }
相关文章推荐
- CoreImage
- 详细讲述iOS自定义转场
- iOS开发 3D-touch使用
- 如何设计一个 iOS 控件?(iOS 控件完全解析)
- Ios和tvos按需请求资源简介
- ios开发之升级Xcode后插件失效解决方法
- iOS图片处理
- 更新更新!重磅出击!【学院官方整理】玩转iOS 8开发,必学的33个经典视频教程
- IOS界面生命周期
- iOS开发之 类目,延展,协议
- iOS开发中MD5的精髓
- Html判断客户端使用的Android还是Ios
- iOS启动动画效果实现
- iOS开发之单例,如何正确的创建单例。
- IOS学习开发路线图
- ios应用内支付过程(使用苹果原生支付方式
- IOS 后台运行申请更多的时间
- iOS实现MD5加密的代码
- iOS常见创建页面的方式
- IOS应用安全(五):高级Runtime分析和操作