我想從url下載圖像並獲取響應對象的NSData。AFNetworking圖像下載不使用AFImageRequestOperation
這是我的設置操作:
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
AFHTTPResponseSerializer *responseSerializer = [AFHTTPResponseSerializer serializer];
responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"image/jpeg"];
manager.responseSerializer = responseSerializer;
AFHTTPRequestSerializer *requestSerializer = [AFHTTPRequestSerializer serializer];
[requestSerializer setValue:@"image/jpeg" forHTTPHeaderField:@"Accept"];
[requestSerializer setValue:@"image/jpeg" forHTTPHeaderField:@"Content-Type"];
manager.requestSerializer = requestSerializer;
[manager GET:url parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSData *data = responseObject;
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
}];
響應對象總是零,網址是正確的,在瀏覽器openned時它顯示圖像時,操作的描述示出了內容長度和內容類型(image/jpeg),但響應對象似乎沒有選取它。
謝謝
答:代替responseObject,operation.reponseData需要使用。
@AdamEberbach它不是重複的,它不是一回事。 – zevonja
你是否在失敗塊中訪問'operation.reponseData'? – vikingosegundo
在成功塊中,不會發生錯誤。 – zevonja