RESTFull Architecture HTTP GET & PUT Requests [clo

2019-06-14 16:32发布

问题:

Could anybody point me to a tutorial, examples or docs about http request, GET, PUT.

I need to put & get a JSON package to & from a URL.

Cant find much objective-c information about receiving JSONs from a HTTP request.

Any help is appreciated.

回答1:

Using AFnetworking Would best Idea.

here is the following example.

 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];
    }];