2013-07-05 109 views
-1

任何人都可以指向關於http請求,GET,PUT的教程,示例或文檔。RESTFULL體系結構HTTP GET&PUT請求

我需要把&從URL中獲取一個JSON包到&。

無法找到很多關於從HTTP請求接收JSON的objective-c信息。

任何幫助表示讚賞。

+0

看看RestKit。 – Wain

+1

是的,RestKit會派上用場。 –

回答

0

使用AFnetworking最好的想法。

這裏是下面的例子。

NSDictionary *parameters = [NSDictionary dictionaryWithObjectsAndKeys:emailUITextView.text, @"email", passwordUITextView.text,@"password", customerType,@"usertype", nil]; 
    NSURL *url = [NSURL URLWithString: BASE_URL]; 
    AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url]; 

    [httpClient postPath:@"/sign_in" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) { 
     NSLog(@"Success : %@", operation.responseString); 
     if([operation.responseString isEqualToString:@"true"]) 
      NSLog(@"Signed In successfully");   
     else if ([operation.responseString isEqualToString:@"false"]) 
      NSLog(@"Signed In unsuccessfully"); 
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) { 
     NSLog(@"Failure : %@", error); 
     UIAlertView *alert = [[ UIAlertView alloc]initWithTitle:@"Error" message:[error localizedDescription] delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil]; 
     [alert show]; 
    }];