I’m new in internet connection for iOS.
I’m trying to get data from special site.
The following codes works great with all site to see the data in the url.
However if I change it the special site to get their data it return NULL!!
I think the site some how block this type of implementation. Because the site present some XML information.
NSString *URLString = @"http://www.specialsite.com/";
NSURL *postURL = [NSURL URLWithString:URLString];
NSURLRequest *postRequest = [NSURLRequest requestWithURL:postURL];
NSURLResponse *response = nil;
NSError *error = nil;
NSData *responseData = [NSURLConnection sendSynchronousRequest:postRequest returningResponse:&response error:&error];
if (responseData) {
NSLog(@"Response was %@", [NSString stringWithCString:[responseData bytes] encoding:NSUTF8StringEncoding]);
}
Also the response in console is:
2011-12-26 12:24:37.245 Arz[6113:207] Response was (null)
Remember if I change:
NSString *URLString = @"http://www.specialsite.com/";
to
NSString *URLString = @"http://www.apple.com/";
working prefect!
Sorry I can’t say the name of the site in here (public).
You can try to use the convenience method:
If this doesn’t work, i would get the response headers using curl from the terminal and see what happens.
Alternatively you can print the response headers just inside XCode when using NSHTTPURLResponse instead:
Look for the response code e.g. HTTP/1.1 200 OK
The response code and the headers will tell you what’s going wrong from the server’s point of view. If the response code is anything else than 200 you will not receive the expected data. Here you can find a list of HTTP Status codes: http://en.wikipedia.org/wiki/List_of_HTTP_status_codes