我一直在試圖下載從URL的圖像(Craigslist的更確切)下載圖像從Craigslist的
首先,我已經使用了SDWebImage框架,我不能看到的圖像。從那以後,我試過一個簡單的方法來下載網址:
使用這個網址的圖片:
http://images.craigslist.org/01212_fxFfHsZFhoi_600x450.jpg
UIImageView image;
NSString *urlstring = [NSString stringWithFormat:@"http://images.craigslist.org/01212_fxFfHsZFhoi_600x450.jpg"];
NSURL *url = [NSURL URLWithString:urlstring];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[image setImageWithURLRequest:request
placeholderImage:[UIImage imageNamed:@"placeholder.png"]
success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image){
// Succes on loading image
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error){
// Fail to load image
}];
,我仍然看不到我的圖像查看圖像。
問題是,如果我更改網址並使用相同的確切代碼,圖像將被下載得很好。我試圖在Safari中加載圖像,它工作得很好,所以鏈接沒問題。
例如我用: http://monsieurstolli.files.wordpress.com/2013/10/meh.jpg
和它的作品。
我不知道如何下載該圖像。
編輯:
我做了一點調查,我改變了代碼:
AFHTTPRequestOperation *requestOperation = [[AFHTTPRequestOperation alloc] initWithRequest:urlRequest];
requestOperation.responseSerializer = [AFImageResponseSerializer serializer];
requestOperation.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];
[requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Response: %@", responseObject);
_imga.image = responseObject;
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Image error: %@", error);
}];
[requestOperation start];
}
,但這個時候,我得到了以下錯誤:
2014-10-16 15:07:10.537 CraigslistChecker[3192:907] Image error: Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: not found (404)" UserInfo=0x1c5b8e30 {com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x1c59ac60>, NSErrorFailingURLKey=images.craigslist.org/00W0W_blCL2sqk1Jt_600x450.jpg, NSLocalizedDescription=Request failed: not found (404), com.alamofire.serialization.response.error.data=<0d0a>}
purgeIdleCellConnections: found one to purge conn = 0x1c59b1f0
請注意,「代碼段」按鈕用於嵌入JavaScript - 不適用於一般代碼示例。改爲使用「代碼示例」按鈕(Ctrl-K)。 – Anna 2014-10-16 12:33:26