0

I want to pull down new images from a website that is updated regularly. However, there is no API for that site, so I'm trying to fetch it by url, as the images are numbered. The way I've decided to do this is have the app query the website on first launch and loop through the URLs until I get a 404. Then I store that URL and on next launch loop through till I get another 404, etc. Now I know that is less than ideal, but I'm just building a prototype. Anyway…

Since these are images we're talking about, I can't just download them all on first launch. Waste of bandwidth, could take minutes or even hours… So I just need a way using NSURLSession or whatever to get the http status code for any given image without actually downloading it.

PopKernel
  • 4,110
  • 5
  • 29
  • 51

1 Answers1

2

You can do this by getting the "HTTP Headers".

This answer will help, if you're comfortable porting Objective-C to help. I can help you with it if required.

Community
  • 1
  • 1
Alexander
  • 59,041
  • 12
  • 98
  • 151
  • Two things: is there a way to do this using NSURLSession or do I have to use NSURLConnection? Also, the example sends the request, doesn't that download the resource? – PopKernel Jun 03 '16 at 19:47
  • That's the difference between `GET` and `HEAD` requests. `HEAD` requests fetch the HTTP headers without actually downloading the fulle content. http://www.perlmonks.org/?node_id=117247 – Alexander Jun 03 '16 at 19:52
  • 1
    Note that a lot of servers don't support HEAD, or support it by just doing a GET - test what happens when you try it... – Wain Jun 03 '16 at 20:02
  • I'll be free in a few hours if you need some more elaboration – Alexander Jun 03 '16 at 20:02