【问题标题】:RESTFull Architecture HTTP GET & PUT Requests [closed]RESTFull 架构 HTTP GET 和 PUT 请求 [关闭]
【发布时间】:2013-07-05 15:27:47
【问题描述】:
谁能指点我有关 http 请求、GET、PUT 的教程、示例或文档。
我需要将 JSON 包放入和从 URL 中获取。
找不到太多关于从 HTTP 请求接收 JSON 的客观 C 信息。
感谢任何帮助。
【问题讨论】:
标签:
objective-c
restful-url
restful-architecture
【解决方案1】:
使用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];
}];