AFNetworking - 向 REST 发送 HTTP POST,发送带有 Base64 字符串图像的 JSON

AFNetworking - Make an HTTP POST to REST, sending a JSON with Base64string image

我正在尝试使用 http POST 和 AFNetworking 在其他一些字符串中发送 base64 编码图像。我正在尝试将参数作为 NSDictionary:

  NSMutableDictionary *info = [NSMutableDictionary dictionary];
    [info setValue:filedata forKey:@"filedata"];
    [info setValue:comments forKey:@"comments"];
    [info setValue:username forKey:@"username"];
    [info setValue:@"jpg" forKey:@"filetype"];
    [info setValue:filename forKey:@"filename"];

和POST 使用 AFNetworking:

AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc]initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    [manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

    [manager POST:@"https://myurl.com/fileupload" parameters:info progress:nil success:^(NSURLSessionTask *task, id responseObject) {
        NSLog(@"JSON: %@", responseObject);
    } failure:^(NSURLSessionTask *operation, NSError *error) {
        NSLog(@"Error: %@", error);
    }];

但是我不确定此时还能做什么。我错过了什么?谢谢

你可以使用下面的例子

AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];

[manager POST:@"https://myurl.com/fileupload" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
    [formData appendPartWithFileData:imageData
                                name:@"key name for the image"
                            fileName:photoName mimeType:@"image/jpeg"];
} success:^(NSURLSessionDataTask *task, id responseObject) {
    NSLog(@"Response: %@", responseObject);
} failure:^(NSURLSessionDataTask *task, NSError *error) {
    NSLog(@"Error: %@", error);
}];