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. 一月份实现Adb小程序

    As Brian said: According to a post on xda-developers, you can enable ADB over WiFi from the device w ...

  2. 西门子SIMATIC IT平台

    西门子公司的SIMATIC IT平台基于ANSI/ISA S95标准开发,包含的功能组件覆盖了ISA S95规定的生产业务操作模型,同时也满足MESA所确定的MES系统11项功能要求. SIMATIC ...

  3. jQuery 插件开发解析

    那么首先我们来简单的看一下最正统的 jQuery 插件定义方式: (function ($) { $.fn.插件名 = function (settings) { //默认参数 var default ...

  4. Oracle并行事务回滚相关参数及视图

    /******相关参数****/fast_start_parallel_rollback1.取值有3种:false,low,high2.各值含义:false  ---禁用并行回滚功能          ...

  5. django-url调度器-初级篇

    Django 遵从 MVC 模型,并将其特色化为 MTV 模型.模型的核心是通过用户访问的 url 来指向处理的函数,而函数处理后返回相应的结果.所以url决定了用户访问的入口,另外表单处理的提交地址 ...

  6. openstack的第二天

    今天,在公司测试了还是网络有问题. 但是用了rdo还是成功了~明天就再试试怎么开放端口进来.

  7. GROUPING SETS、CUBE、ROLLUP

    其实还是写一个Demo 比较好 USE tempdb IF OBJECT_ID( 'dbo.T1' , 'U' )IS NOT NULL BEGIN DROP TABLE dbo.T1; END; G ...

  8. DB2缓冲池、表空间

    在DB2中建立表空间得指向该表空间所属缓冲池,否则表空间指向默认缓冲池 1.缓冲池 1.1 创建缓冲池 语法:CREATE BUFFERPOOL <bp_name> SIZE <nu ...

  9. Linux/Android 系统怎么修改mac地址

    使用 busybox ifconfig eth0 hw ether AA:BB:CC:DD:EE 可以修改, 但是每次重启都会改回原来的. 所以要修改 /etc/init.mini210.sh (可能 ...

  10. 2.Knockout.Js(监控属性Observables)

    前言 1.创建一个ViewModel <script type="text/javascript"> //1.创建一个ViewModel var myViewModel ...