I am using objective C and I am trying to load a website without opening it in Safari :
I am using the following function :
NSString *website =[NSString stringWithFormat:@"http://www.website.com"];
NSString *connected = [NSString stringWithContentsOfURL:[NSURL URLWithString:website ]encoding:NSStringEncodingConversionAllowLossy error:nil];
but when I check in my database I noticed that it does not load the website , when I load it in the browser it does detect it tho , any reasons ?
thanks
You probably want to use the
NSURLConnectionclass to retrieve data from the network. It will provide a much more useful set of errors, etc.For simple (but blocking), you can start off with
-sendSynchronousRequest:returningResponse:error:, which retrieves a URL from the network giving you the data (in the return value), the HTTP Response, and an error.If data isn’t nil, you’ve gotten a valid response, otherwise error contains information about the response. You still need to double-check the
responsein order to make sure you got what you wanted (not a “successful” response that resulted in an error due to the server sending back an error code for HTTP).In the future, if you need to do a POST command, you can use NSMutableURLRequest and set the type of the request.