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! While you're at it, check out some resources Treehouse students have shared here.
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 trialalex3
5,387 PointsGot 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
Saif Zaza
3,188 PointsThis is the solution
Greg Kaleka
39,021 PointsHi 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?
alex3
5,387 PointsYes, 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
Courses Plus Student 6,923 PointsDo 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
Hamish Lockie
5,088 Points@ Pablo, that's the error that I got - my response was Null.
I had found the same in one of the earlier courses too.
https://teamtreehouse.com/community/xcode-7-ios9-error-uri-transport
That link contains a solution.
I believe that the default setting was changed, which is why you need to do this step.
alex3
5,387 PointsThe link isn't valid.
Hamish Lockie
5,088 PointsSorry, some random markup on the end.
If you remove the characters after transport it will work.