1、报文头需要密码验证的

- (void)sendAsynWebServiceRequest:(NSString *)nameSpace method:(NSString *)method requestXmlString:(NSString *)requestXmlString

{

NSString *sRequestXmlString = [requestXmlString stringByReplacingOccurrencesOfString:@"<" withString:@"&lt;"];

sRequestXmlString = [sRequestXmlString stringByReplacingOccurrencesOfString:@">" withString:@"&gt;"];

NSString *soapMessage = [NSString stringWithFormat:

@"<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\n"

"<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:encodingStyle=\"http://www.w3.org/2001/12/soap-encoding\">\n"

"<soap:Body>\n"

"<%@  xmlns=\"%@%@\">\n"

"<xml>%@\n%@</xml>\n"

"<verifyID>123456</verifyID>\n"

"</%@>\n"

"</soap:Body>\n"

"</soap:Envelope>",method,BASEURL,nameSpace,@"&lt;?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?&gt;",sRequestXmlString,method];

DMLog(@"发送的soap信息====%@",soapMessage);

tagName = method;

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@",BASEURL,nameSpace]];

NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url];

[urlRequest setTimeoutInterval:120.0];

NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];

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

[urlRequest addValue: [NSString stringWithFormat:@"%@%@/%@",BASEURL,nameSpace,method] forHTTPHeaderField:@"soapAction"];//SOAPAction http://210.51.27.9:8080/dtlp/ws/service

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

[urlRequest setHTTPMethod:@"POST"];

[urlRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

2、不需要密码验证的

NSString *sRequestXmlString = [requestXmlString stringByReplacingOccurrencesOfString:@"<" withString:@"&lt;"];

sRequestXmlString = [sRequestXmlString stringByReplacingOccurrencesOfString:@">" withString:@"&gt;"];

NSString *soapMessage = [NSString stringWithFormat:

@"<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\n"

"<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:encodingStyle=\"http://www.w3.org/2001/12/soap-encoding\">\n"

"<soap:Body>\n"

"<%@  xmlns=\"%@%@\">\n"

"<xml>%@\n%@</xml>\n"

"</%@>\n"

"</soap:Body>\n"

"</soap:Envelope>",method,BASEURL,nameSpace,@"&lt;?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?&gt;",sRequestXmlString,method];

DMLog(@"发送的soap信息====%@",soapMessage);

tagName = [NSString stringWithFormat:@"%@Return",method];

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@",BASEURL,nameSpace]];

NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url];

[urlRequest setTimeoutInterval:120.0];

NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];

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

[urlRequest addValue: [NSString stringWithFormat:@"%@%@/%@",BASEURL,nameSpace,method] forHTTPHeaderField:@"soapAction"];//SOAPAction http://210.51.27.9:8080/dtlp/ws/service

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

[urlRequest setHTTPMethod:@"POST"];

[urlRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];

3、解析返回的数据

-(NSString*)getBusinessXML:(NSString*)xmlStr xmltagName:(NSString*)xmltagName{

NSString *regEx = [[NSString alloc] initWithFormat:@"<%@ >[\\w\\W]*</%@>", xmltagName, xmltagName];

NSString *sxmlstr = [xmlStr stringByReplacingOccurrencesOfString:@"xsi:type=\"xsd:string\"" withString:@""];

NSRange range = [sxmlstr rangeOfString:regEx options:NSRegularExpressionSearch];

if(range.location != NSNotFound){

NSString *businessXML = [sxmlstr substringWithRange:range];

//替换特殊字符

businessXML = [businessXML stringByReplacingOccurrencesOfString:@"&lt;" withString:@"<"];

businessXML = [businessXML stringByReplacingOccurrencesOfString:@"&gt;" withString:@">"];

businessXML = [businessXML stringByReplacingOccurrencesOfString:@"&amp;" withString:@"&"];

businessXML = [businessXML stringByReplacingOccurrencesOfString:@"&quot;" withString:@"'"];

businessXML = [businessXML stringByReplacingOccurrencesOfString:@"&apos;" withString:@"\""];

businessXML = [businessXML stringByReplacingOccurrencesOfString:@"&lt;" withString:@"<"];

businessXML = [businessXML stringByReplacingOccurrencesOfString:@"&gt;" withString:@">"];

//去除tagname

// businessXML = [businessXML substringWithRange:NSMakeRange(tagName.length+2, businessXML.length-(tagName.length*2+5))];

NSRange range1 = [businessXML rangeOfString:@"<?" ];

NSRange range2 = [businessXML rangeOfString:@"?>"];

if (range1.location !=NSNotFound && range2.location != NSNotFound) {

NSRange ranng = NSMakeRange(range1.location, range2.location - range1.location + 2);

businessXML = [businessXML stringByReplacingCharactersInRange:ranng withString:@""];

}

return businessXML;

}

return DATAANALYZEFAIL;

}

ios中webservice报文的拼接的更多相关文章

  1. iOS中支付宝集成

    iOS中支付宝集成 如今各种的App中都使用了三方支付的功能,现在将我在使用支付宝支付集成过程的心得分享一下,希望对大家都能有所帮助 要集成一个支付宝支付过程的环境,大致需要: 1>公司:先与支 ...

  2. iOS中的存储方式

    1.Plist 1.1 了解沙盒 每个iOS应用都有自己的应用沙盒(应用沙盒就是文件系统目录),与其它文件系统隔离.应用必须呆在自己的沙盒里.其它应用不能访问该沙盒. 一个程序中所有的非代码文件都可以 ...

  3. iOS中发送HTTP请求的方案

    在iOS中,常见的发送HTTP请求的方案有 苹果原生(自带) NSURLConnection:用法简单,最古老最经典的一种方案 NSURLSession:功能比NSURLConnection更加强大, ...

  4. IOS中调用系统的电话、短信、邮件、浏览功能

    iOS开发系列--通讯录.蓝牙.内购.GameCenter.iCloud.Passbook系统服务开发汇总 2015-01-13 09:16 by KenshinCui, 26990 阅读, 35 评 ...

  5. iOS 中的加密方式

    iOS 中的加密方式 1 加密方式主要有: Base64,MD5,RSA,DES,AES,钥匙串存储,Cookie 2 各加密方式的比较 2.1 Base64 2.1.1 基本原理:采用64个基本的 ...

  6. ios 中的小技巧 - 总有你想要的 一

    UITableView的Group样式下顶部空白处理 在viewWillAppear里面添加如下代码: //分组列表头部空白处理 CGRect frame = myTableView.tableHea ...

  7. QF——iOS中的数据库操作:SQLite数据库,第三方封装库FMDB,CoreData

    SQLite数据库: SQLite是轻量级的数据库,适合应用在移动设备和小型设备上,它的优点是轻量,可移植性强.但它的缺点是它的API是用C写的,不是面向对象的.整体来说,操作起来比较麻烦.所以,一般 ...

  8. iOS中 CoreGraphics快速绘图(详解) 韩俊强的博客

    每日更新关注:http://weibo.com/hanjunqiang  新浪微博 第一步:先科普一下基础知识: Core Graphics是基于C的API,可以用于一切绘图操作 Core Graph ...

  9. iOS中GET 和 POST 数据请求

    iOS中GET 和 POST 网络数据请求 同步请求和异步请求的差别: 1.同步请求,有主线程完成网路请求任务,在数据没有请求之前,用户的所有的交互事件应用都无法处理,会造成一种卡顿现象,影响用户体验 ...

随机推荐

  1. xmpp push篇一 广播消息

    ---广播给所有人--- 1. 登录xmpp admin 账户 2. sendpacket <message to="pandans.com(域名)" > <bo ...

  2. javascript中方法调用与方括号[]

    看jquery时遇到一行: $(this)["removeClass"]("selected"); 这一行等同于下面的一行: $(this).removeCla ...

  3. Python判断是否是数字(无法判断浮点数)(已解决)

    s为字符串s.isalnum() 所有字符都是数字或者字母s.isalpha() 所有字符都是字母s.isdigit() 所有字符都是数字s.islower() 所有字符都是小写s.isupper() ...

  4. C 基于UDP实现一个简易的聊天室

    引言 本文是围绕Linux udp api 构建一个简易的多人聊天室.重点看思路,帮助我们加深 对udp开发中一些api了解.相对而言udp socket开发相比tcp socket开发注意的细节要少 ...

  5. RMAN - 备份异机恢复

    OS: Oracle Linux Server release 5.7 DB: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - ...

  6. 九度oj 1528 最长回文子串

    原题链接:http://ac.jobdu.com/problem.php?pid=1528 小白书上的做法,不过这个还要简单些... #include<algorithm> #includ ...

  7. 开启Objective-C --- OC基础知识

    一.Objective-C简述      Objective-C通常写作ObjC和较少用的Objective C或Obj-C,是扩充C的面向对象编程语言.Objective-C主要用于:编写iOS操作 ...

  8. 61.MII、RMII、GMII接口的详细介绍

    概述: MII (Media Independent Interface(介质无关接口)或称为媒体独立接口,它是IEEE-802.3定义的以太网行业标准.它包括一个数据接口和一个MAC和PHY之间的管 ...

  9. Java实现Socket之TimeClient

    Java实现Socket之TimeClient 代码内容 从time.nist.gov服务器的37号端口得到时间信息,并对时间进行解析后显示出来 代码实现 /* TimeClient.java */ ...

  10. 【学习总结】iOS中NSNotification、delegate、KVO三者之间的区别与联系?

    在开发ios应用的时候,我们会经常遇到一个常见的问题:在不过分耦合的前提下,controllers间怎么进行通信.在IOS应用不断的出现三种模式来实现这种通信: 1.委托delegation: 2.通 ...