I have an app with 100k+ users that connects using a SOAP web service. Everything works fine for most users except sometimes using NSURLConnection I keep getting the error:
Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost." UserInfo=0xac16c70 {NSErrorFailingURLStringKey=https://mail.scripps.org:443/ews/Exchange.asmx, NSErrorFailingURLKey=https://mail.scripps.org:443/ews/Exchange.asmx, NSLocalizedDescription=The network connection was lost., NSUnderlyingError=0x133b0eb0 "The network connection was lost."}
This only happens for certain servers. The servers have NTLM authentication which works 95% of the time but for some reason I'm getting the error and I have no idea why.
Any help appreciated.
This Question also identified the problem I was having.
Instead of soap, I'm using jsonrpc.
The solution was simple. I needed:
[myMutableURLRequestObject setHTTPMethod:#"POST"];
Network connection failures happen, you just need to handle them gracefully. One solution may be to retry the connection 1 or more times until it succeeds after you are sure there is a network connection. Rough example below:
if([error domain] == NSURLErrorDomain &&
[error code] == NSURLErrorNetworkConnectionLost &&
retryCount < kMaxRetryCount)
{
[self retry];
++retryCount;
}
Related
I need to determine no internet exception when connecting to server without network. But on iOS I get IOException(On Android exception is ConnectException).
The message of exception contains this error message:
Error Domain=NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline." UserInfo={NSUnderlyingError=0x10bc06330 {Error Domain=kCFErrorDomainCFNetwork Code=-1009 "(null)" UserInfo={_kCFStreamErrorCodeKey=50, _kCFStreamErrorDomainKey=1}}, NSErrorFailingURLStringKey=http://..., NSErrorFailingURLKey=http://..., _kCFStreamErrorDomainKey=1, _kCFStreamErrorCodeKey=50, NSLocalizedDescription=The Internet connection appears to be offline.}`
I can parse this message and check if it contains Code=-1009. But, is there a more elegant way to check NSError from JavaLangException?
Unfortunately, there currently isn't a better way. We tried extending changing java.lang.Throwable's superclass to NSException, but that caused more problems than it solved. It also doesn't make sense to define new exception classes for each iOS networking error code, as that would increase the size of each app that uses j2objc. Consider using something like: if (exception.getMessage().contains("NSURLErrorDomain Code=-1009")) ... or define a isConnectionOffline(Exception e) method that does this check as well as one for Android.
You could file an enhancement request for some sort of NSURLErrorDomain exception wrapper, which could make these errors easier to decipher. Better yet, we love contributions if you come up with something useful. ;-)
My iOS app use RestKit framework for implementing RESTful web services client.
Sometimes, I have a problem when I call my server from my application.
The request is not sent and it fails at the end of the expiration with this error:
Error Domain=NSURLErrorDomain Code=-1001 "The request timed out."
At the first openning, it is impossible to reproduce this.
The problem occurs when the application is put into the background and it restarts 10 minutes later or more (it does not produce every time). At this point, there is no server side call .
Then, the only way to solve this problem is to force-quit the application.
We checked there is no error of url, of header, etc ...
HELP ME :'(
Try to set time interval like
[manager.requestSerializer setTimeoutInterval:yourTimeInterval];
Generally, while performing GET or POST calls in iOS using dataTaskWithRequest or sendAsynchronousRequest we use to face network related errors with error codes like,
NSURLErrorNotConnectedToInternet = -1009
NSURLErrorCannotConnectToHost = -1004
NSURLErrorTimedOut = -1001
In my case i'm disconnecting the internet and performing service calls. So, the expected error code is "NSURLErrorNotConnectedToInternet = -1009". But, its throwing "NSURLErrorCannotConnectToHost = -1004" like below,
Error Domain=NSURLErrorDomain Code=-1004 "Could not connect to the
server." UserInfo=0x1700f0e00 {NSUnderlyingError=0x170255e70 "The
operation couldn’t be completed. (kCFErrorDomainCFNetwork error
-1004.)", NSErrorFailingURLStringKey=https://example.com/reg,
NSErrorFailingURLKey=https://example.com/reg, _kCFStreamErrorDomainKey=1,
_kCFStreamErrorCodeKey=51, NSLocalizedDescription=Could not connect to the server.}
So, how to get the exact error status while using dataTaskWithRequest or sendAsynchronousRequest.
As a rule, IIRC, the OS sends "not connected to Internet" only in two situations:
The network is determined to be nonfunctional after:
One or more URL requests fail and
The OS tries to probe a well-known captive-portal-detection URL and
That request also fails
No interface has an IP address
Including any connected VPNs
Excluding loopback interface
Up until the system reaches that state, the failures you see will be "cannot connect to host", because that's all the OS knows for certain.
As a rule, your app should interpret these in the same way — by using reachability to determine when to try again, then trying again when reachability changes.
I am using AfNetworking 1.0 into my app.I have created a singleton class of AFHTTP Client.
So all the API's are place in the same class.
I am getting a very wierd issue.
For eg: Let say, i have requested for some data from server.But the internet connection has lost.
So the failure block get's called.
m getting the following error:
Error Domain=NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline." UserInfo=0x797dcc70 {NSErrorFailingURLStringKey=https://testing.com?searchText=s&pageSize=10&pageNumber=5, _kCFStreamErrorCodeKey=57, NSErrorFailingURLKey=https://testing.com?searchText=s&pageSize=10&pageNumber=5, NSLocalizedDescription=The Internet connection appears to be offline., _kCFStreamErrorDomainKey=1, NSUnderlyingError=0x7aa367e0 "The Internet connection appears to be offline."}
But if i try to get the status code using following code:
NSLog(#"Status code %d",[operation.response statusCode]);
m getting Status Code as "0".
Can you please explain,why i am getting Status code as "0"?
I have to handle the error,depends on HTTP Status Code.So what is the best way to get this done?
(the same way which i am doing or is there any other way.)
In this case you can't use the status code because there isn't one. The status code comes from the server and in this case the client has not been able to contact the server.
You should use the error domain and code to handle this case.
I have an iPhone application in which I have a request which works fine on wifi and with all network carriages but one carriage. On this carriage, if I use ASIHttpRequest, it gives me the below error:
ASIHTTPRequest request_didFail: Error Domain=ASIHTTPRequestErrorDomain Code=1 "A connection failure occurred" UserInfo=0xd54e2f0 {NSUnderlyingError=0xd502de0 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error 2.)", NSLocalizedDescription=A connection failure occurred}
If I use AFNetworking it returns below error:
NSLocalizedDescription = "Could not connect to the server.";
NSUnderlyingError = "Error Domain=kCFErrorDomainCFNetwork Code=-1004 \"Could not connect to the server.\" UserInfo=0xdc98630 {NSErrorFailingURLKey=https://sitename.com, NSErrorFailingURLStringKey=https://sitename.com, NSLocalizedDescription=Could not connect to the server.}";
First of all, what could be the reason of this error assuming it only happens for a specific carrier? Second, as the request works with everything but this carriage, it seems hard to debug, so how can I debug it to find the exact problem?
Thanks
It turned out that the problem was with this specific telco. Without changing the code, it started to work again after some time.
For the answer to this question, I can say that the reason could be about some proxy thing that is made by the telco and we tried to debug it by applying different proxy tests.