Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Photo Browser iPhone App Downloading Data with NSURLSession NSURLSession Basics

Got Forbidden instead of json data

I just need these recent blog posts!

Here is my NSURL Code:

NSURLSession *session = [NSURLSession sharedSession];
NSURL *url = [[NSURL alloc] initWithString:@"http://blog.teamtreehouse.com/api/get_recent_summary/"];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
NSURLSessionDownloadTask *task = [session downloadTaskWithRequest:request completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) {
        NSString *text = [[NSString alloc] initWithContentsOfURL:location encoding:NSUTF8StringEncoding error:nil];
        NSLog(@"Response: %@", text);
    [task resume];

4 Answers

Greg Kaleka
Greg Kaleka
39,021 Points

Hi Alexander,

I don't actually know a whole lot of Objective-C, but I can see you have one opening curly brace and two closing braces. That's likely where your problem comes from.

Let us know if that solves it.

OK, looking at the video, I'm guessing that extra closing curly brace is actually closing viewDidLoad(), so that's not your problem.

Your code seems to match the video. If you copy and paste the url http://blog.teamtreehouse.com/api/get_recent_summary/ into your browser (or just click this link), do you see JSON data?

Yes, I do. I've no idea where the problem is. I tried to access the JSON Data with the teachers project and it had worked. After that I pasted the whole viewDidLoad method in my code hoping it'll work but it doesn't. So there is no issue with my viewDidLoad method i guess.

Pablo Alfaro
Pablo Alfaro
Courses Plus Student 6,923 Points

Do you get the error that states you can not make a connection over HTTP? This error to be exact ----> App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure

@ Pablo, that's the error that I got - my response was Null.

I had found the same in one of the earlier courses too.


That link contains a solution.

I believe that the default setting was changed, which is why you need to do this step.

The link isn't valid.

Sorry, some random markup on the end.

If you remove the characters after transport it will work.