微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

soap协议

首先给大家普及一下soap是干什么用的,其实soap是一个访问协议,用来像webservice传输xml格式数据,soap请求消息的格式如下:

<?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/\"  xmlns:标识名=命名空间>

<soap:Body>

<标识名:方法名><paramString>参数</paramString></标识名:方法名>

</soap:Body>

</soap:Envelope>

(标识名可以自己定义:比如name等)

好了以上就是soap消息的标准格式,用它就可以进行下边的数据请求了:

//请求发送到的路径

NSURL *url = [NSURLURLWithString:URL];

NSMutableuRLRequest *theRequest = [NSMutableuRLRequestrequestWithURL:url];

Nsstring *msgLength = [NsstringstringWithFormat:@"%d",[soap消息 length]];

//以下对请求信息添加属性前四句是必有的,第五句是soap信息。

[theRequest addValue:@"text/xml; charset=utf-8"forHTTPHeaderField:@"Content-Type"];

[theRequest addValue:@""forHTTPHeaderField:@"SOAPAction"];

[theRequestaddValue: msgLengthforHTTPHeaderField:@"Content-Length"];

[theRequestsetHTTPMethod:@"POST"];

[theRequest setHTTPBody: [soap消息 dataUsingEncoding:NSUTF8StringEncoding]];

//请求

NSURLConnection *theConnection = [[NSURLConnectionalloc]initWithRequest:theRequestdelegate:self];

//如果连接已经建好,则初始化data

if( theConnection )

{

 _webData = [[NSMutableDatadata]retain];

}

else

{

 NSLog(@"theConnection is NULL");

}


链接已经建立好之后就要开始接收数据了:


下边的这个函数就是接受和处理服务器返回来的数据

-(void)connectionDidFinishLoading:(NSURLConnection *)connection

{

    //注意这里要把你请求回来的数据转换成UTF8

    Nsstring* response = [[Nsstringalloc]initWithData:_webDataencoding:NSUTF8StringEncoding];

   NSLog(@"==========%@",response);

    [responserelease];

    [connection release];

    NSData *xmlData = [returnStringdataUsingEncoding:NSUTF8StringEncoding];

   _doc = [[DDXMLDocumentalloc]initWithData:xmlDataoptions:0error:nil];

    进行解析数据..........

}

好了以上就是soap请求的完整步骤,至于xml解析有很多种方法,这里就不一一介绍了,拿到返回数据你就可以解析出你想要的小编了。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐