zoukankan      html  css  js  c++  java
  • IOS使用soap。

    - (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);
    }
    
  • 相关阅读:
    算法疑难(js实现)---5、变态跳台阶
    算法疑难(js实现)---4、跳台阶(记忆化递归)
    算法疑难(js实现)---3、两个栈来实现一个队列
    算法疑难(js实现)---2、重建二叉树
    Ext的Panel总结(好文章)
    Extjs datefield 日历控件中文显示
    EXTJS项目实战经验总结一:日期组件的change事件:
    ExtJs内的datefield控件选择日期过后的事件监听select
    ExtJs FormPanel布局
    开发extjs常用的插件
  • 原文地址:https://www.cnblogs.com/youyuan1980/p/5026655.html
Copyright © 2011-2022 走看看