【问题标题】:AFNetworking - add "image\jpeg" content type to AFImageResponseSerializerAFNetworking - 将“image\jpeg”内容类型添加到 AFImageResponseSerializer
【发布时间】:2014-09-30 00:46:25
【问题描述】:

我正在尝试从 Facebook 的来源加载图片(我通过我的应用上传并保存了来源的图片)。 我正在使用 AFNetworking 来处理我所有的网络需求,但是当我尝试从以下位置加载图片时:

http://fbcdn-sphotos-e-a.akamaihd.net/hphotos-ak-xfa1/v/t1.0-9/s720x720/10314676_10152739718934904_452946709678730535_n.jpg?oh=7e73d62e46c33e541e559e07e12bf275&oe=54B7E8CB&gda=1421866048_e364ab835ea15826e7ff28c8382ac085

(在浏览器中打开,或者在我在 http 生成器中设置的常规 http get 请求中打开)但是从 AFNetworking 中它总是收到错误请求 (403) 错误..

我认为因为来自服务器的响应将是 image\jpeg 并且我已经准备好默认情况下它不适用于 AFNetworking..

如何将它添加到序列化器中?还是我应该写一个新的 http 请求?

【问题讨论】:

    标签: ios facebook afnetworking


    【解决方案1】:

    imageView.imageResponseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"image/jpeg", @"image/jpg"];

    【讨论】:

      【解决方案2】:

      我最终使用了:

      -(void) loadPictureFromUrl:(NSString*)urlString {
          NSURL* url = [NSURL URLWithString:urlString];
          NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
          [NSURLConnection sendAsynchronousRequest:request
                                             queue:[NSOperationQueue mainQueue]
                                 completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
                                     if ( !error )
                                         [_httpRequestDelegate httpResponseReceived:nil responsedData:[[UIImage alloc] initWithData:data]];
                                     else
                                         [_httpRequestDelegate httpRequestReturnedError:nil withError:error];
                                 }];
      }
      

      而不是与 AfNetworking 对抗 - 这通常很棒,但我正在尝试做的事情有问题

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-11-22
        • 2016-06-09
        • 2016-06-15
        • 2012-09-16
        • 2016-02-15
        相关资源
        最近更新 更多