Home > Uncategorized > Making a HTTP request from objective C

Making a HTTP request from objective C


I don’t normally write about objective C, since I’m not experienced in programming in that language, but I thought I’d post this really crucial, yet simple way to make a HTTP request in objective C, and get a string (NSString) back

NSString *dataUrl = @”https://yourAPI.com/something”;

    NSURL *url = [NSURL URLWithString:dataUrl];

    NSURLSessionDataTask *downloadTask = [[NSURLSession sharedSession]

    dataTaskWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error)


        if (error)


           // report  error.localizedDescription to the user.



        NSString *content = [[NSString alloc]



       // Now Content contains the returned data.


    [downloadTask resume];

Categories: Uncategorized
  1. February 12, 2017 at 12:22 am

    And don’t forget to set ATS if you need to call a HTTP endpoint




  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: