我想用 POST 方法发出请求,然后我希望他们返回 json 数据或NSDictionary
,但他们只能在成功时返回字符串
像 NSString *response = [operation responseString];
任何人都知道如何让他们返回NSdictionary
而不是NSString
?
-(IBAction)SubmitLogin:(id)sender{
NSLog(@"Login");
// NSLog(@"%@",username);
//START FUNGSI UNTUK POST, PUT, DELETE
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:signinUrl];
[httpClient defaultValueForHeader:@"Accept"];
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
@"someuser", @"username",
@"somepassword",@"password",
nil];
NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST"
path:@""
parameters:params];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[httpClient registerHTTPOperationClass:[AFHTTPRequestOperation class]];
[operation setCompletionBlockWithSuccess:
^(AFHTTPRequestOperation *operation,
id responseObject) {
NSString *response = [operation responseString];
NSLog(@"response: %@",response);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"error: %@", [operation error]);
}];
//call start on your request operation
[operation start];