RESTFull 架构 HTTP GET &PUT 请求
问题描述:
谁能给我指点有关 http 请求、GET、PUT 的教程、示例或文档.
Could anybody point me to a tutorial, examples or docs about http request, GET, PUT.
我需要把 &获取一个 JSON 包到 &从一个网址.
I need to put & get a JSON package to & from a URL.
找不到很多关于从 HTTP 请求接收 JSON 的 Objective-c 信息.
Cant find much objective-c information about receiving JSONs from a HTTP request.
感谢任何帮助.
答
使用 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];
}];