Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 822405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:47:40+00:00 2026-05-15T02:47:40+00:00

I have this code NSString *tr = [self sendUrl:@http://google.com/]; But for some reason ‘

  • 0

I have this code

   NSString *tr = [self sendUrl:@"http://google.com/"];

But for some reason ‘tr‘ will remain nil after it is executed. What am I doing wrong?

sendUrl :

- (NSString *)sendUrl:(NSString *) uri {

NSLog(@"Requesting URI 1 ...");

// Prepare URL request to download statuses from Twitter
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:uri]];

NSLog(@"Requesting URI 2 ...");

// Perform request and get JSON back as a NSData object
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];

NSLog(@"Requesting URI 3 ...");

// Get JSON as a NSString from NSData response
NSString *json_string = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];

NSLog(@"Requesting URI 4 ...");

return json_string;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T02:47:41+00:00Added an answer on May 15, 2026 at 2:47 am

    Are you absolutely certain that response is not nil? If your request to Google or wherever fails, response will be set to nil and the error will contain some information that will help you diagnose the error so change

    NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
    

    to

    NSError* error = nil;
    NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error];
    if (response == nil)
    {
        NSLog(@"request failed with error %@", error);
        // any other error handling
    }
    

    Next thing. The default encoding for an HTTP message is ISO-8859-1, not UTF-8. According to Apple’s docs, -initWithData: will return nil if the encoding is wrong. You probably want NSISOLatin1StringEncoding. I say “probably” because HTTP has a mechanism for telling you what character encoding it used. I think it’s the header Content-Transfer-Encoding but I advise you to Google the HTTP RFC to find out for sure.

    Finally if json_string were not nil, it would be leaking. Because you obtained it with alloc, you own it which means you need to autorelease it before returning it from sendURL: This last point is not the cause of your problem, it is a separate bug in your code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 535k
  • Answers 535k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can do this without using regex, by using some… May 17, 2026 at 1:08 am
  • Editorial Team
    Editorial Team added an answer Use the filter_var PHP function instead: if (filter_var($email, FILTER_VALIDATE_EMAIL)) {… May 17, 2026 at 1:08 am
  • Editorial Team
    Editorial Team added an answer Just use the .not() method. It accepts a list of… May 17, 2026 at 1:08 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have this code that can't send a Facebook request until now. NSDictionary *firstDict
I have this code in my drawRect method float aValue = .0167f; float fValue
So i have this very basic ipad view controller and i was doing some
I'm currently using this code NSHost *host = [NSHost hostWithAddress:hostname]; if (host == nil)
Alright, so I'm running into an issue with my code. What I have done
I'm stuck with the following bit of code. NSString *gridRef = [[NSString alloc] initWithFormat:
I have a uiviewcontroller with two properties: trackName and playerObject. PlayerObject also has a
I have a UIPickerView object that has five rows that a user can select.
I get a null return when i try out my NSString function. //Track.m static
I have the error -[NSCFString stringValue]: unrecognized selector sent to instance 0x1578c when executing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.