iphone开发笔记五 asihttprequest访问websevice

前面搭好了webservice后就可以开始url http访问,一开始没有看到现成的例子访问。但是在论坛里都推荐使用asihttprequest这个插件。所以直接去调查asihttprequest的用法,http://www.cnblogs.com/dotey/archive/2011/05/10/2041966.html这篇写的比较详细

没有使用ios自带的估计自带的写起来比较费事。等到项目快做完才发现asihttprequest已经没人维护了,在ios5下有问题,果断新项目放弃。调查mknetworkkit,这个据说是比asihttprequest还要好。

一,下载asihttprequest

http://allseeing-i.com/ASIHTTPRequest/

二,配置asihttprequest

1、拷贝项目下面的文件到项目中去,我是把所有文件豆放入一个包下面导入进去的。

2、点击项目jar包管理,asihttprequest引用到的包。

三、使用

在m文件中引入ASIHTTPRequest.h文件,然后开始调用

//  http
-(void) grabURL{
    NSString *strurl = [[NSString alloc]initWithFormat:@"%@Menu/findAllMenus",webServiceUrl];
    NSURL *url = [NSURL URLWithString:strurl];
    [strurl release];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request startSynchronous];
    NSError *error = [request error];
    NSLog(@"%@",error);
    if (!error) {
        NSString *response = [request responseString];
        NSLog(@"%@",response);
        [self parseGdatexml:response];
        
    }
    
}


    

Using ASIHTTPRequest in an iOS project

1) Add the files

Copy the files you need to your project folder, and add them to your Xcode project. An overview of the ASIHTTPRequest source files appears here.

If you aren't sure which files you need, it's best to copy all the following files:

  • ASIHTTPRequestConfig.h
  • ASIHTTPRequestDelegate.h
  • ASIProgressDelegate.h
  • ASICacheDelegate.h
  • ASIHTTPRequest.h
  • ASIHTTPRequest.m
  • ASIDataCompressor.h
  • ASIDataCompressor.m
  • ASIDataDecompressor.h
  • ASIDataDecompressor.m
  • ASIFormDataRequest.h
  • ASIInputStream.h
  • ASIInputStream.m
  • ASIFormDataRequest.m
  • ASINetworkQueue.h
  • ASINetworkQueue.m
  • ASIDownloadCache.h
  • ASIDownloadCache.m

iPhone projects must also include:

  • ASIAuthenticationDialog.h
  • ASIAuthenticationDialog.m
  • Reachability.h (in the External/Reachability folder)
  • Reachability.m (in the External/Reachability folder)

2) Link with CFNetwork, SystemConfiguration, MobileCoreServices, CoreGraphics and zlib

Open the settings for your target by clicking on the blue bar at the very top of the Xcode sidebar:



Open the Build Phases tab, expand the box labeled Link Binary With Libraries then click the plus button.



Choose CFNetwork.framework from the list, and click Add:



Repeat the last two steps to add the following: SystemConfiguration.frameworkMobileCoreServices.framework,CoreGraphics.framework and libz.dylib.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值