Nsurlerrordomain Error 401
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business nshttpurlresponse status code 401 Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation
Nsurlconnection Status Code 401
Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like nsurlerrorusercancelledauthentication you, helping each other. Join them; it only takes a minute: Sign up iOS: How can i receive HTTP 401 instead of -1012 NSURLErrorUserCancelledAuthentication up vote 31 down vote favorite 15 I have a problem similar to nsurlerrordomain code 1012 the operation couldn t be completed the one described in the link below. NSHTTPURLResponse statusCode is returning zero when it should be 401 I use [NSURLConnection sendSynchronousRequest:returningResponse:error:] to get data from a server. When NSURLConnection receives the HTTP Code 401, it does not return anything but an error object with code -1012 from the NSURLErrorDomain. -1012 corresponds to NSURLErrorUserCancelledAuthentication. Since I have to parse the HTTP Header I need to get the original error and not what NSURLConnection made out of
Nserror
it. Is there a way to receive the original 401 http packet? iphone http ios nsurlconnection share|improve this question edited Jan 13 '11 at 20:29 Moshe 30.3k56209356 asked Oct 12 '10 at 7:47 Tomen 3,55542135 2 I am having this exact same problem. –Marc W Jan 13 '11 at 17:15 Have you looked into ASIHTTPRequest? –Moshe Jan 13 '11 at 20:29 1 I'd rather stick with built-in APIs if possible. FWIW, checking the NSError out-param for NSURLErrorUserCancelledAuthentication works fine. It just seems odd that when a status 401 is returned, the NSURLResponse out-param is left nil. –Marc W Jan 13 '11 at 23:30 add a comment| 4 Answers 4 active oldest votes up vote 16 down vote accepted +150 Yes. Stop using the synchronous API. If you use the asynchronous delegate-based API then you have a lot more control over the connection. With this API, except in cases where an error is encountered before the HTTP header is received, you will always receive -connection:didReceiveResponse:, which gives you access to the HTTP header fields (encapsulated in an NSURLResponse object). You can also implement authentication using the relevant delegate methods if you are so inclined. share|improve this answer answered Jan 13 '11 at 20:22 Kevin Ballard 120k17283282 Doing authentication with the delegate message is unnecessarily chatty, especially since the creden
Sign in Pricing Blog Support Search GitHub This repository Watch 23 Star 534 Fork 40 dingbat/nsrails Code Issues 1 Pull requests 1 Projects 0 Wiki Pulse Graphs New http 401 issue Handling of 401 response #26 Closed ata-n opened this Issue Nov 12, 2012 · 3 comments Projects None yet Labels None yet Milestone No milestone Assignees No one assigned 2 participants ata-n commented Nov 12, 2012 First off, awesome job on this light and powerful library! thank you. Second: is there a way to handle http status codes? I http://stackoverflow.com/questions/3912532/ios-how-can-i-receive-http-401-instead-of-1012-nsurlerrorusercancelledauthenti know they are being bubbles to the NSError object in every call, but I get different errors (namely an appleError as oppose to a railsError) when my server sends a 401! heres my log: 2012-11-11 20:01:02.441 ViewDeckExample[50073:c07] [NSRails][OUT] ===> GET to http://localhost:3000/api/v1/me 2012-11-11 20:01:02.515 ViewDeckExample[50073:c07] [NSRails][connection] Error Domain=NSURLErrorDomain Code=-1012 "The operation couldn’t be completed. (NSURLErrorDomain error -1012.)" UserInfo=0x845f310 {NSErrorFailingURLKey=http://localhost:3000/api/v1/me, NSErrorFailingURLStringKey=http://localhost:3000/api/v1/me, NSUnderlyingError=0x845ebb0 "The operation couldn’t https://github.com/dingbat/nsrails/issues/26 be completed. (kCFErrorDomainCFNetwork error -1012.)"} I am using Doorkeeper gem on the backend and its issuing the 401 correctly, but here I like to catch it and pop open a login window or something any thoughts? Thanks again Owner dingbat commented Nov 12, 2012 Ah yes, a 401 Unauthorized will be caught as an error by NSURLConnection because I think it sees it as a flat-out connection refusal. This is in the same class as, say, a connection issue, a badly formed URL, time out, etc. I considered for a minute on making an exception for this error code and bubbling it up as a 401 NSRails error, but I think that'd be a bit arbitrary, and we're not even sure it'd always be a 401 (stupidly we can't get the original error code out of Apple's response.) So, I would just treat it as the NSError that it is. You can make sure the domain is NSURLErrorDomain, and then test the error code for unauthorized (-1012). A list of NSURL error codes can be found here. I'd do something like this: error.domain == NSURLErrorDomain && (error.code == NSURLErrorUserAuthenticationRe
not post a blank message. Please type your message and try again. This discussion is locked daniel738 Level 1 https://discussions.apple.com/thread/1700673?start=0&tstart=0 (0 points) Q: How to get original HTTP error code in NSUrlRequest/NSUrlConnection? Hi allIn my iPhone app I'm calling some webservices. Doing so, it can happen that something goes wrong. Since the user has to provide some authentication data, MANY things may go wrong and I like to give as status code precise feedback as possible about the reason, why the request failed.I'm using NSUrlRequest/NSUrlConnection to connect the webserver.-----...NSMutableURLRequest *theRequest = [ NSMutableURLRequest requestWithURL: url ];....NSURLConnection *theConnection= [[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; ----- I then get the error messages in the delegate method:------ (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error-----Now to my question:As far as I status code 401 can see, all I get is this NSError. E.g. it's a "NSURLErrorUserCancelledAuthentication", but the webserver responded with a HTTP 401 error! Is there any chance to get the underlaying error code originally returned by the webserver? Another error often returned is "NSURLErrorDomain error -1012". This means nothing to a user. Is the a proper way to handle these errors? I tried with [error localizedDescription], but these "translations" are not meaningful either.Any hints and help are appreciated.Thanks in advanceDanielPS: sorry the bad formatting. I did'nt figure out how to proper format code and text Mac OS X (10.5.4) Posted on Sep 9, 2008 5:46 AM I have this question too Close Q: How to get original HTTP error code in NSUrlRequest/NSUrlConnection? All replies Helpful answers by orangekay, orangekay Sep 9, 2008 8:47 AM in response to daniel738 Level 5 (4,085 points) Sep 9, 2008 8:47 AM in response to da