RESTFul架构HTTP GET和; PUT请求

时间:2013-07-05 15:27:48

标签: objective-c restful-url restful-architecture

有人能指出我关于http请求,GET,PUT的教程,示例或文档。

我需要把&获得一个JSON包给&来自一个URL。

无法找到有关从HTTP请求接收JSON的更多客观信息。

感谢任何帮助。

1 个答案:

答案 0 :(得分: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];
    }];