2011-06-13 7 views
-1

我是新來iphone ....當我需要連接到一個Web服務我使用的是follwing代碼是使用ASIHTTP請求..當我添加此代碼它的未來錯誤如何connectASIHTTPRequest爲WebService

ASIHTTPRequest未申報聲明它第一個我shd申報和wat我shd聲明?我正在使用UIViewController類

我怎麼shd申報?笏我SHD辦?PLZ建議我下面

-(void)callWebService 

{ 

    //this is a typical url for REST webservice, where you can specify the method that you want to call and the parameters directly with GET 

    NSURL *url = [NSURL URLWithString:@"http://www.yourserver.net/webservice/rest/?method=myMethod&par1=ok"]; 

    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; 

    [request setDidFinishSelector:@selector(requestCompleted:)]; 

    [request setDidFailSelector:@selector(requestError:)]; 

    [request setDelegate:self]; 

    [request startAsynchronous]; 
} 

- (void)requestCompleted:(ASIHTTPRequest *)request 
{ 

    NSString *responseString = [request responseString]; 

} 

- (void)requestError:(ASIHTTPRequest *)request 
{ 

    NSError *error = [request error]; 

} 

代碼給出感謝ü...

,你必須附加在你的項目asihttp包

回答

2

首先檢查。 之後,檢查是否具有

#import "ASIHTTPRequest.h"進口這在您的視圖 - 控制

不要忘記檢查你是否貼有以下框架。 CFNetwork,SystemConfiguration,MobileCoreServices,CoreGraphics和libz框架。

你還沒有告訴要使用哪種方法

[request setRequestMethod:@"GET"]; BEFORE [request startAsynchronous]; 

當你右鍵點擊這個彈出會出現框架文件夾。 enter image description here

enter image description here

+0

@Abhilash是你的問題解決了。 – Gypsa 2011-06-13 05:38:57

+0

@Abhilash框架文件夾右鍵單擊選擇添加現有的框架彈出將顯示那裏你會得到它。 – Gypsa 2011-06-13 05:46:36

+0

謝謝你...如何添加ashihttp包?以及此MobileCoreServices和libz框架位於我沒有得到它 – Abhilash 2011-06-13 05:47:04