iOS-AFN Post JSON格式資料
阿新 • • 發佈:2018-11-27
- (void)postRequest{ AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; // >>>>>>>> post 傳送json格式資料的時候加上 manager.requestSerializer = [AFJSONRequestSerializer serializer]; manager.responseSerializer = [AFJSONResponseSerializer serializer]; // <<<<<<<<[manager.requestSerializer setValue:@"token_String" forHTTPHeaderField:@"Authorization"]; NSString *url = @""; NSDictionary *postData = @{@"data1":@"one",@"data2":@"two"}; [manager POST:url parameters:postData progress:^(NSProgress * _Nonnull uploadProgress) { } success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { }]; }