加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

soap协议

发布时间:2020-12-16 23:12:41 所属栏目:安全 来源:网络整理
导读:首先给大家普及一下soap是干什么用的,其实soap是一个访问协议,用来像webservice传输xml格式数据,soap请求消息的格式如下: ?xml version="1.0" encoding="utf-8"? soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ? ? ? ? ?

首先给大家普及一下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解析有很多种方法,这里就不一一介绍了,拿到返回数据你就可以解析出你想要的东东了。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读