0

I am creating an iOS app in which I want to test several servers with a HTTP request. The app needs to look at a plist file with all the servers to test and expected end results, then execute the test and return a response code (i.e.: 200, 404, etc)

This information needs to then be saved to a server for later evaluation.

The problem I am having is I am unable to find a good viable way to just test a server. I don't need to download anything or save any content from the server, just test it.

How might some of you go about this? AFNetworking? Reachability? NSURLConnection?

Thanks!

Brian
  • 723
  • 1
  • 8
  • 26

2 Answers2

1

You can use NSURLConnection to issue a simple GET request to the server (i.e, http://www.google.com) and check the response code. You have several delegate methods, for successful and failed request.

This can be done using this example https://stackoverflow.com/a/6918832/975959

Issuing a GET request is pretty simple with NSURLConnection. for example, see here

Good luck.

Community
  • 1
  • 1
La bla bla
  • 8,558
  • 13
  • 60
  • 109
  • Thank you for the help. I will try using NSURLConnection. Any chance you know a good resource to do this with AFNetworking? – Brian Jun 03 '13 at 18:54
  • I've never used AFNetworking myself, only ASIHTTPRequest, but a quick Google lead to this: http://samwize.com/2012/10/25/simple-get-post-afnetworking/ which looks like a good place to start. Also, If you think this is the correct answer, please accept it. Good luck – La bla bla Jun 03 '13 at 21:54
  • Gave AFNetworking a shot and NSURLConneciton a shot. Both seem to do what I want to do. Querying things is a bit tough but both are viable solutions. Thanks for the help. – Brian Jun 05 '13 at 21:13
1

Reachability checks if the network is reachable or not, it won't get any status codes back. Probably not what you want.

Instead, you probably want to make HEAD requests. They're basically the same thing as GET, only, without a response body. You can use NSURLConnection for this, or AFNetworking (which is a wrapper on top of NSURLConnection).

zadr
  • 2,505
  • 18
  • 19