NSString *username = emailField.text; NSString *password = passwordField.text; NSMutableDictionary *dictionnary = [NSMutableDictionary dictionary]; [dictionnary setObject:@"admin" forKey:@"username"]; [dictionnary setObject:@"123456" forKey:@"password"]; NSError *error = nil; NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dictionnary options:kNilOptions error:&error]; NSString *urlString = @"Sample URL"; NSURL *url = [NSURL URLWithString:urlString]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; [request setHTTPMethod:@"POST"]; [request setHTTPBody:jsonData]; NSURLResponse *response = NULL; NSError *requestError = NULL; NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&requestError]; NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding] ; NSLog(@"%@", responseString);
返回值
/index.php/api/transaction/model/transactionsuccess?username=admin&password=12123
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/index.php/api/transaction/model/transactionsuccess?username=admin&password=12123"]]; // Perform request and get JSON as a NSData object NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; NSLog(@"response=%@",response );