NSString *url = [NSString stringWithFormat:@"%@%@oauth/token",AFURL,authGatway];
NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:url parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFormData:[@"password" dataUsingEncoding:NSUTF8StringEncoding] name:@"grant_type"];
[formData appendPartWithFormData:[username dataUsingEncoding:NSUTF8StringEncoding] name:@"username"];
[formData appendPartWithFormData:[password dataUsingEncoding:NSUTF8StringEncoding] name:@"password"];
[formData appendPartWithFormData:[@"*****************" dataUsingEncoding:NSUTF8StringEncoding] name:@"client_id"];
[formData appendPartWithFormData:[@"*****************" dataUsingEncoding:NSUTF8StringEncoding] name:@"client_secret"];
} error:nil];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
NSURLSessionUploadTask *uploadTask;
uploadTask = [manager
uploadTaskWithStreamedRequest:request
progress:^(NSProgress * _Nonnull uploadProgress) {
}
completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
if (error) {
NSLog(@"Error: %@", error);
} else {
NSLog(@" %@", responseObject);
}
}];
[uploadTask resume];
[formData appendPartWithFormData:[@"password" dataUsingEncoding:NSUTF8StringEncoding] name:@"grant_type"];
以键值对的方式向服务器传输数据