I have to load all the required details from server in my application. eg; I wants to load countries detail from the following URL.
https://sub.domain.com//members/phone/XML_list_countries.php
But I am getting following error. But the same request working in Simulator.
ERROR
Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo=0x3b8d10 {NSErrorFailingURLStringKey=https://secure.nymgo.com//members/softphone/XML_list_countries.php, NSErrorFailingURLKey=https://secure.nymgo.com//members/softphone/XML_list_countries.php, NSLocalizedDescription=The request timed out., NSUnderlyingError=0x3b5090 "The request timed out."}
CODE
NSURL *url=[NSURL URLWithString:#"https://secure.nymgo.com//members/softphone/XML_list_countries.php"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:#"GET"];
NSURLConnection *_connection = [[NSURLConnection alloc] initWithRequest:_request delegate:self];
if(!_connection){
NSLog(#"Can not make this request.");
}
I have implemented all the required delegate methods.
NOTE: My device is working in Wifi with proxy settings.
I don't know what is going wrong. Please help me to resolve this issue.
Have you Implement :
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge;
Also Refer this SO post.
You can use the ASIHTTPRequest framework also.
I have tested the same code in different iPhone 3G and iPhone 4 devices. it is working fine.
NOTE: I searched lot in google. I got lot of result. One of the result is like "some iPhone 3G is not supporting for HTTPS. So I decided to test it in different devices.
Related
I'm trying to determine whether or not the user enabled push notification for my app using phonegap (ver 1.7).
So far I only came up with this plugin which doesn't have a method specifically to check that issue, but does have a method to register push notification, which may return an error, which may be an indication to the user disabling push notification. But as you can see, that's very vague.
So my question is - is there a plugin (or any other way) to determine if the user enabled push notification for my app?
You can check if any type of push notifications are enabled by using this :
if([UIApplication sharedApplication].enabledRemoteNotificationTypes == UIRemoteNotificationTypeNone)
this status can be accesd by call a simple plugin after device ready.
UPDATE :Write a plugin and inside that plugin please check the status and return to javascript
if you need to save it on server first thing you need one server side api and some native side code, after registering push notification on ios there are two callback functions
didFailToRegisterForRemoteNotificationsWithError
didRegisterForRemoteNotificationsWithDeviceToken
so if success you can send a request to your server with the device id or any unique ID so you can save the registered devices.
(void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
NSString *token = [[[[deviceToken description] stringByReplacingOccurrencesOfString:#"< "withString:#""] stringByReplacingOccurrencesOfString:#">" withString:#""]
stringByReplacingOccurrencesOfString: #" " withString: #""];
[self postUpdateRequest:token]; // request to your server
}
for sending POST request use
NSURL *aUrl = [NSURL URLWithString:uRI];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:aUrl cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
[request setHTTPMethod:#"POST"];
NSString *postString =#"Your Data";
[request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *connection= [[NSURLConnection alloc] initWithRequest:request
delegate:self];
[connection start];
if(connection) {
// success
} else {
//error
}
if registration was failed (didFailToRegisterForRemoteNotificationsWithError) you can send a requset to server with error data OR Not.
from phonegap side after device ready send one ajax request to you server and check whether your device is registerted or not. for getting unique id you may use simple plugin. for writing simple plugin please follow this http://docs.phonegap.com/en/edge/guide_hybrid_plugins_index.md.html#Plugin%20Development%20Guide
Unfortunately you can't enable or disable the Push Notifications for your app from the app code. check this
My situation is this:
I have a UIWebView which makes a POST request to a URL where the hostname is provided by the user.
When the hostname does not exist, I need to timeout so that I can alert the user to say that they should check the their settings.
What is happening:
I make a request like this:
NSString *theURL = [NSString stringWithFormat:#"https://%#%#", _hostname, LOGIN_PART_URL];
NSString *body = [NSString stringWithFormat:#"Username=%#&Password=%#", _username, _password];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:theURL]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:_timeoutInSecs];
[request setHTTPMethod: #"POST"];
[request setHTTPBody: [body dataUsingEncoding: NSUTF8StringEncoding]];
[web loadRequest:request];
When the hostname does not exist on the network, I do not get any timeout response.
I have implemented all delegate methods of UIWebViewDelegate, and I get the following called in order when I use a non-existent hostname:
webView: shouldStartLoadWithRequest: navigationType:
(returns true always for testing)
webViewDidStartLoad
And that's it - nothing after that.
I'm surprised that webViewDidStartLoad gets called, as this would suggest that it found the URL and thinks it can get data back from it. But it can't as the URL does not exist!
Am I doing something wrong here?
I have a workaround which I am going to implement, which uses an NSTimer to see if a response has been received within the timeout period. However, I am having issues with cancelling a request for a UIWebView - but that's a topic for my next SO question!
So my questions:
Is it correct for webViewDidStartLoad to be called on an invalid URL?
Should I be seeing a request timeout error returned, with the way I have setup my request?
Thanks in advance!!
Stretch :)
Use delegate method
webView:didFailLoadWithError:
Get the error from it. If the error code is
-1000 - Bad Url
-1001 - Request timed out
-1003 - Cannot find host
-1004 - Cannot connect to host
-1005 - Network connection lost
-1006 - NSLookupFailed
By checking this you can alert the user about the error.
I am using ASIHTTPRequest in my project and i have a problem with iPhone 3G.
i send a request to :
NSURL* pageURL = [NSURL URLWithString:#"https://accounts.google.com/ServiceLogin?service=sj"];
loginPageRequest = [[ASIHTTPRequest alloc] initWithURL:pageURL];
[loginPageRequest setTimeOutSeconds:30];
[loginPageRequest setDelegate:self];
[loginPageRequest startAsynchronous];
and in other devices i get a responde to :
- (void)requestFinished:(ASIHTTPRequest *)request
and in iPhone 3G i get a lot of times :
- (void)requestFailed:(ASIHTTPRequest *)request
with error MSG : The request timed out
i set the the request timeout to 30 seconds.
any idea why it happen?
I also had this problem on iPhone 3G!
I figured out it was a HTTP*S* (SSL) problem. My "valid" certificate was flagged as invalid.
You might add [request setValidatesSecureCertificate:NO]; to your request.
If you are lucky you have the same problem. :)
I need a little help here!!!
If string 'url' contains the address to web server, how do i check whether my web server is up or down?
I got some codes to check Internet connectivity. But even if we have internet connectivity how do we know server is up or not? Is there any better way to do that?
Thank You
You could do a request,
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:url]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:20.0];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest
delegate:self];
Now if you implement (along with all other delegate methods)
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
you will get either succes or error.
Post a request, get the response. If you get a response, the server is up, if not its down..
I'm using the ASIHTTPRequest lib in my iOS app to make RESTful requests to my Rails 3 web app. I seeing a weird and somewhat consistent error the 1st time I try to make a POST request to my web app, but then the POST request works fine the on the second attempt. The exact error is...
Error Domain=ASIHTTPRequestErrorDomain Code=1 "A connection failure occurred" UserInfo=0xb513740 {NSUnderlyingError=0xb5135a0 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1005.)", NSLocalizedDescription=A connection failure occurred}
And here's my ASIHTTPRequest code for making the POST request...
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"http://myrails3app.heroku.com/tournaments/%d/register.json", tid]];
__block ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setRequestMethod:#"POST"];
[request addPostValue:username forKey:#"username"];
[request setCompletionBlock:^
{
NSData *responseData = [request responseData];
NSLog(#"Success!");
}];
// Set the code to be called when the request fails
[request setFailedBlock:^
{
NSError *error = [request error];
NSLog(#"Error: %#", [error localizedDescription]);
}];
// Start the request
[request startAsynchronous];
It's worth mentioning that when it errors out, it errors out incredibly quickly! Also, for what it's worth, my Rail 3 app that I'm making the POST request to is hosted on Heroku. Your thoughts?
Thanks so much for your wisdom!
This issue I had a lot of hard time to figure out why. The problem resides in ASIHTTPRequest itself (iOS), not the rails code.
To make a long story short, the problem is specific to the use of persistent connection for every request sent by ASIHTTPRequest.
While this is good for GET requests, most server implementation does not allow persistent connection to be used with POST request.
I didn't really have time to investigate it deeply on the server side of things but I think that the problem resides with the 100-Continue header that should be sent (and which isn't) with request that has body attached to it (hence PUT/POST). If you want to have a deeper look at what I'm talking about go have a read at the spec sheet: http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html
So the persistent connection used by ASIHTTPRequest wait for a 100 response to be sent, which is never sent. so it ends up being timed out.
A fix is to set persistentConnection to NO with your post requests like the following:
ASIHTTPRequest *req = [ASIHTTPRequest requestWithURL:url];
req.shouldAttemptPersistentConnection = NO;
Secure Connection Failed
An error occurred during a connection to login.yahoo.com.
SSL received a record with an incorrect Message Authentication Code.
(Error code: ssl_error_bad_mac_read)
The page you are trying to view can not be shown because the authenticity of the received data could not be verified.
Please contact the web site owners to inform them of this problem. Alternatively, use the command found in the help menu to report this broken site.
On iOS 5.1, even after upgrading ASIHTTPRequest to ASIHTTPRequestVersion = #"v1.8.1-61 2011-09-19" still needed:
ASIHTTPRequest *req = [ASIHTTPRequest requestWithURL:url];
req.shouldAttemptPersistentConnection = NO;
i also had to set response setHeader Connection to "close" in by Java servlet
response.setHeader("Connection", "close");