AFNetWorking POST Multi-Part Request 上传图片

这些天来,做图片上传的时候,我遇到一个问题。对我来说,这只是一个附加的图片将请求超时,这里是代码:

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    NSURL *filePath = [NSURL URLWithString:[NSString stringWithFormat:@"file://%@",fullPath]];
    [manager POST:url parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        [formData appendPartWithFileURL:filePath name:@"image" error:nil];

    } success:^(AFHTTPRequestOperation *operation, id responseObject) {
        

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];


由于我这边除了要上传图片之外,还有其它的数据,所以採用AFNetWorking的POST Multi-Part Request进行数据提交。

碰到的问题就是:仅仅要不上传图片就没有问题,我一加入append...就会请求超时。后来更新了一下AFNetWorking就ok了,挺怪的。也许是iOS8的原因吧!

https://github.com/AFNetworking/AFNetworking/

欢迎批评!

版权声明:本文博主原创文章,博客,未经同意不得转载。

原文地址:https://www.cnblogs.com/bhlsheji/p/4839566.html