NSURLConnection didFailWithError not called?

女生的网名这么多〃 提交于 2019-12-02 05:45:28

问题


Why, when an image does not exist at a specified URL, does didFailWithError not get called? For example:

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com/images/someImageIknowDoesntExist.jpg"] 
                     cachePolicy:NSURLRequestReturnCacheDataElseLoad
                             timeoutInterval:10.0];

        urlConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];

Does not trigger didFailWithError. How can I get notified that there is no image at the url I try to connect to?


回答1:


The status code in the response will be 404 when you get the connection:didReceieveResponse: method. The error method only gets called if there was an actually error fetching the URL (like the network went down, or the host doesn't exist, etc).



来源:https://stackoverflow.com/questions/3982598/nsurlconnection-didfailwitherror-not-called

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!