これは、私の古いプロジェクト (AFNetworking および JSON-response) の 1 つの実例です。
- (void) loadItems:(NSString*)searchText
{
NSString *surl = [NSString stringWithFormat:@"http://localhost:8888/index.php?s=%@", searchText];
NSURL *url = [NSURL URLWithString:surl];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[AFJSONRequestOperation addAcceptableContentTypes:[NSSet setWithObject:@"text/html"]]; //content-type is not set properly by the server
AFJSONRequestOperation *operation =
[AFJSONRequestOperation JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSLog(@"Done: %@", JSON);
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON){
NSLog(@"failure: %@", [error description]);
}];
[operation start];
}
お役に立てれば。
POST リクエストについては、この回答を確認することもできます:
AFNetworking - How to make POST request