2011-07-15 57 views
0

我第一次使用Webservices,我有一個URL。我必須將我的登錄ID和密碼發佈到該URL,以便我可以將somae xml格式發回給我。如何使用URL驗證用戶?

請給我一個例子。

在此先感謝, Rizwan。

+0

這是通過點擊答案旁邊的勾號來完成的。 –

回答

0

You can use ASIHTTPRequest for the same as follows

NSString *userName = @"yourUserName"; 
NSString *password = @"yourPassword"; 

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:strURL]]; 
[request setDelegate:self]; 
[request setPostValue:userName forKey:@"UserName"]; 
[request setPostValue:password forKey:@"Password"]; 
[request startAsynchronous]; 

在這裏,我們已經設置委託給自己,所以有2個委託方法實施如下。

- (void)requestFinished:(ASIHTTPRequest *)request 
{ 
    // Fetch your xml response here and parse it. 
    NSString *responseString = [request responseString]; 
} 

- (void)requestFailed:(ASIHTTPRequest *)request 
{ 
    NSError *error = [request error]; 
} 

這是簡單的方法,你可以用ASIHTTPRequest做很多事情。有關詳細信息,請訪問documentation