iOS-AFN Post JSON格式數據

- (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) {
       
    }];
}
相關文章
相關標籤/搜索