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

webService 编程

发布时间:2020-12-16 23:17:07 所属栏目:安全 来源:网络整理
导读:这段时间,一直都在搞 webService 编程和 socket 编程,搞的死去活来的。总算是有点了解和认识,现在作笔录:p一,webService源代码/p NSString *url = [NSString stringWithFormat:@"?xml version="1.0" encoding="utf-8"?soap:Envelope xmlns:xsi="ht

这段时间,一直都在搞 webService 编程和 socket 编程,搞的死去活来的。总算是有点了解和认识,现在作笔录:<p>一,webService源代码</p>        NSString *url = [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><%@ xmlns="http://www.zgbeidou.cn/"><username>%@</username><password>%@</password>
<servicepassword>YFGPS2008</servicepassword></%@></soap:Body></soap:Envelope>",type,nil,type];

?NSString *urlLength = [NSString stringWithFormat:@"%d",[url length]];

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

?[urlRequest addValue:urlLength forHTTPHeaderField:@"Content-Length"];

?NSString *SOAPAction_str = [NSString stringWithFormat:@"http://www.zgbeidou.cn/%@",type];

?[urlRequest addValue:SOAPAction_str forHTTPHeaderField:@"SOAPAction"];

?[urlRequest setHTTPMethod:@"POST"];

?[urlRequest setHTTPBody:[url dataUsingEncoding:NSUTF8StringEncoding]];

?//请求并接收返回的数据 

 NSURLResponse *reponse;

?NSError *error = nil;

?NSData *responseData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&reponse error:&error];

?NSMutableString *resultString = [[NSMutableString alloc]initWithData:responseData encoding:NSUTF8StringEncoding];

?//    NSLog(@"urlRequest = %@",resultString);

?//解析xml数据

?GDataXMLDocument *doc = [[GDataXMLDocument alloc]initWithData:responseData options:0 error:nil];

?GDataXMLElement *rootElement = [doc rootElement];
 
    NSData *data = [[rootElement stringValue]dataUsingEncoding:NSUTF8StringEncoding];

?NSArray *arr = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];

?NSLog(@"arr22222 = %@",arr );
?

(编辑:李大同)

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

    推荐文章
      热点阅读