Are HTTP status codes anywhere in the iOS SDK?

Does anyone know if / where the HTTP status codes, as indicated here , are defined in the iOS SDK? Or do I need to manually override them in the constant file?

+57
ios objective-c
Apr 22 '11 at 4:10
source share
6 answers

I did

grep -r '404' * 

at

 /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/System/Libβ€Œβ€‹rary/Frameworks/ 

and came up empty-handed, so the answer is almost certainly no.

+22
Jun 22 '11 at 17:53
source

Well, they are defined in the sense that

 [NSHTTPURLResponse localizedStringForStatusCode:(NSInteger)statusCode] 

can return a string for a given status code. Is this what you are looking for?

+24
Apr 22 '11 at 4:21
source

There is a complete Obj-C library with all the codes defined to date: https://github.com/rafiki270/HTTP-Status-Codes-for-Objective-C

+6
Oct 07 '13 at 16:53 on
source

I also could not find the header file that I expected should exist, so I had to write one of my own.

With the HTTPStatusCodes.h contained in the nv-ios-http-status project on GitHub, sending by HTTP status codes can be written as follows.

 #import "HTTPStatusCodes.h" ...... - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { NSHTTPURLResponse *res = (NSHTTPURLResponse *)response; switch ([res statusCode]) { // 200 OK case kHTTPStatusCodeOK: ......; } ...... } 

I hope HTTPStatusCodes.h can save you time and other developers.

+2
Apr 20 '13 at
source

The http status code can be determined by the server responder. When there is a connection, you can use NSURLResponse to read the statusCode. These 4 ** responses can be defined inside your server.

+1
Jun 22 '11 at 18:35
source
+1
Jun 14 '16 at 12:19
source



All Articles