之前发送请求传给后台的参数都是通过requestParm的,而现在要改成走RequestBody的。
代码如下:
// 请求头
NSString *accessPath = @"http://119.254.126.188/app/userRegister/sendPhoneMsg";
// 请求参数字典
NSDictionary *params = @{@"mobie":@"W7YYWEtJaOxQSmTDqPb1EPtS4NqvVASpAgbSQP3f045XqXdwdIxf6f2aRXZD4%2BZj%2B28DkktLlV2JrgtiOWO7PQWarUZ2MhCeeZg%2FBTZzjQLzOMAkY5t%2ByQR0OxoziejIzlDOHhKMQoJxWDfp9t0aBkm3%2B%2BC%2BXQlVsSpmoCZboO4%3D", @"name":@"2"};
NSLog(@"发送请求url=%@,params=%@",accessPath,params);
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
NSMutableURLRequest *request = [[AFJSONRequestSerializer serializer] requestWithMethod:@"POST" URLString:accessPath parameters:params error:nil];
request.timeoutInterval = 10.f;
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
NSURLSessionDataTask *task = [manager dataTaskWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
NSLog(@"-----responseObject===%@+++++",responseObject);
if (!error) {
if ([responseObject isKindOfClass:[NSDictionary class]]) {
// 请求成功数据处理
} else {
}
} else {
NSLog(@"请求失败error=%@", error);
}
}];
[task resume];