IOS访问webserver接口

接口调用参数只能是字符串格式,返回格式支持3种(字符串,数组,DataSet)

需要引用第三方库,包含(DataSet,PlatServinceDataParser,WebserviceCommon,WebServiceHelper,XMLArrayParser,XMLDataSetParser,XMLResultParser)

程序中引用2个即可

#import "WebServiceCommon.h"

#import"DataSet.h"

- (void)getwebserver

{

WebServiceCommon *webService=[[WebServiceCommonalloc] init];

//方法一,取返回字符串

NSString *result= [webServicegetResultWithURL:@"http://116.6.52.27:91/webservice/caskaforescService.asmx"xmlNS:nilmethod:@"GetCarTypeTree"pars:nil];

NSLog(@"%@",result);

[result release];

//带参数传值调用方法

NSMutableDictionary *dic=[[NSMutableDictionaryalloc]initWithObjectsAndKeys:@"test2",@"username",@"820826",@"passWord",@"1EB2D9848C5545E6BAEAA10B01222800",@"clubUserid",@"西南大区",@"BigArea",@"",@"province",@"",@"city",nil];

NSString *result2= [webServicegetResultWithURL:@"http://116.6.52.27:91/webservice/caskaforescService.asmx"xmlNS:nilmethod:@"GetClub"pars:dic];

NSLog(@"%@",result2);

[dic release];

[result2 release];

//方法二,取返回数据组

NSArray *array=nil;

NSMutableDictionary *dic2=[[NSMutableDictionaryalloc]initWithObjectsAndKeys:@"...",@"VerifyCode", @"",@"objParams",@"20120615170225282486",@"sAccountBookID", @"XYTY124",@"productModel", @"馨原奕绒",@"brandName", nil];

array=[webServicegetArrayWithURL:@"http://resourceservice.41go.cn/systemupdate.asmx"xmlNS:nilmethod:@"GetProductPriceInfoExt"pars:dic2];

NSLog(@"productmodel=%@;name=%@,key=%@",[arrayobjectAtIndex:2],[arrayobjectAtIndex:3],[arrayobjectAtIndex:10]);

//判断数据中的空值(NSArray,NSMutableDictionary等)

if ([array objectAtIndex:10]==[NSNullnull]) {

NSLog(@"空值!");

}

[dic2 release];

//方法三,取返回DataSet

[webServiceinitDataSetWithURL:@"http://resourceservice.41go.cn/systemupdate.asmx"xmlNS:nilmethod:@"GetYarnList"pars:nil];

NSMutableDictionary *wb=[webService.myDataset.TablesobjectForKey:@"YarnList"];//YarnList表名,如果没有命名则为Table

NSInteger count=[[webService.myDataset.TablesobjectForKey:@"YarnList"]count];

for (int ii=0; ii<count; ii++) {

NSMutableDictionary *dictemp=[wb objectForKey:[NSStringstringWithFormat:@"%d",ii]];

NSLog(@"col1=%@;col2=%@;col3=%@",[dictempobjectForKey:@"C_AccountBookID"],[dictempobjectForKey:@"C_Name"],[dictempobjectForKey:@"C_YarnID"]);

}

[webService release];

}

时间: 2024-08-27 19:42:14

IOS访问webserver接口的相关文章

iOS访问相册及拍照保存的实现实例

iOS访问相册及拍照保存的实现实例 实现效果: 1.点击访问相册按钮,可以访问系统相册,选择以后返回在imageView中显示 2.点击拍照,访问摄像头,实现以后保存在相册中,返回在imageView中显示 注意:拍照功能需要真机调试,模拟器无法实现 模拟器会有如下效果~弹出警告框 工程下载:github工程下载链接 下面是程序:注意此例中两个button和UIimageView在storyboard中添加: ViewController.h @interface ViewController

iOS.访问 Web Service.MKNetworkKit_POST

#import <UIKit/UIKit.h> #import "T20140628025249NSNumber+Message.h" #import "T20140628025249NSString+URLEncoding.h" #import "MKNetworkEngine.h" #import "MKNetworkOperation.h" @interface T20140628025249ViewCont

iOS.访问 Web Service.同步GET请求方法

1.字符串转换为URL字符串NSString分类 #import <Foundation/Foundation.h> @interface NSString (URLEncoding) -(NSString *)URLEncodedString; -(NSString *)URLDecodedString; @end #import "T20140628013418NSString+URLEncoding.h" @implementation NSString (URLEn

iOS.访问通讯录.01.读取联系人信息

1.相关函数介绍 1.创建通讯录对象函数 ABAddressBookRef ABAddressBookCreateWithOptions( CFDictionaryRef options, CFErrorRef *error ); 例子: CFErrorRef error = NULL; ABAdressBookRef addressBook = ABAdressBookCreateWithOptions(NULL,&error); ABAddressBookRequestAccessWithC

iOS.访问 Web Service.异步GET请求方法

#import <UIKit/UIKit.h> #import "T20140628024750NSNumber+Message.h" #import "T20140628024750NSString+URLEncoding.h" @interface T20140628024750ViewController : UITableViewController<NSURLConnectionDelegate> @property (nonato

iOS.访问 Web Service.异步POST请求方法

#import <UIKit/UIKit.h> #import "T20140628024917NSNumber+Message.h" #import "T20140628024917NSString+URLEncoding.h" @interface T20140628024917ViewController : UITableViewController<NSURLConnectionDelegate> @property (nonato

iOS.访问通讯录.00.概述

1.移动设备上都有一个很重要的内置数据库 -- 通讯录,苹果把它扩展到了iCloud上,使苹果设备间可以共享通讯录信息. 2.在iOS上,通讯录放在SQLite3数据库中,但是应用之间不能直接访问,也就是说我们自己编写的应用不能采用数据持久化技术直接访问通讯录数据库.为了实现通讯录数据库的访问,苹果开放了一些专门的API. 3.处于安全考虑,iOS6之后的应用访问通讯录时,需要获得用户的授权,与其他应用(如定位服务授权)不同的是,通讯录对一个应用只授权一次,即便是这个应用删除后重新安装,也不必再

iOS.访问 Web Service.MKNetworkKit_GET

#import <UIKit/UIKit.h> #import "T20140628025200NSNumber+Message.h" #import "T20140628025200NSString+URLEncoding.h" #import "MKNetworkEngine.h" #import "MKNetworkOperation.h" @interface T20140628025200ViewCont

数据访问层接口

IDBObject(数据访问层接口) Contents IDBObject ExecuteProcedure(string storedProcName, IDataParameter[] parameters) RunProcedure RunProcedure(string storedprocName, IDataParameter[] parameters, OperateReader OReader) RunProcedure(string storedprocName, IDataP