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

  • Home
  • SEARCH
  • 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 7829849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:56:21+00:00 2026-06-02T10:56:21+00:00

some codes in httpController.h like this: @interface httpController:NSObject{ … NSMutableData *receivedData; } @property (nonatomic,retain)

  • 0

some codes in httpController.h like this:

@interface httpController:NSObject{
  ...
  NSMutableData *receivedData;
}
@property (nonatomic,retain) NSMutableData *receivedData;

and some codes in httpController.m file like this:

@implementation httpController
@synthesize receivedData;
...
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
  [receivedData setLength:0];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data               
{
  if (!receivedData) {
      receivedData = [[NSMutableData alloc] init];
  }
  [receivedData appendData:data];  
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {

}

Then I want using the receivedData in the main.m file, like this:

int main(int argc, const char *argv[])
{
   HttpController *httpController = [[HttpController alloc] init];
   NSURLRequest *request = ...;
   NSURLConnection *connetion = ...;
   if(connection)
   {
     NSMutableData *_receviedData = httpController.receivedData;
     NSString * dataString = [[[NSString alloc] initWithData:_receviedData encoding:NSUTF8StringEncoding] autorelease]; 
     NSLog(@"%@",dataString);
   }
   [[NSRunLoop currentRunLoop] run];
}

But i found that in the main() function, the value of _receivedData is empty, and there is noting outputted. Anyone can tell me What’s wrong about it?

  • 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-06-02T10:56:26+00:00Added an answer on June 2, 2026 at 10:56 am

    +connectionWithRequest:delegate: runs asynchronously. It looks like it’s not finishing the connection before returning, which is why you don’t see any data. Try +sendSynchronousRequest:returningResponse:error: instead, as this will block the thread until the connection finishes.

    There’s no need for a HttpController/delegate when using +sendSynchronousRequest:returningResponse:error: either. Here’s how to do it:

    int main(int argc, const char *argv[])
    {
        NSURL           *url        = [NSURL URLWithString:@"http://www.yahoo.com/"];
        NSURLRequest    *request    = [NSURLRequest requestWithURL:url];
        NSURLResponse   *response   = nil;
        NSError         *error      = nil;
    
        // This blocks "this" thread until it's done.
        NSData          *data       = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    
        if (!data)
        {
            NSLog(@"Error: %@", error);
        }
        else
        {
            NSString *dataString = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
            NSLog(@"%@", dataString);
        }
    }
    

    If you don’t want to block the thread, then +connectionWithRequest:delegate: is the way to go. But you’ll have to write your code differently, and should read the docs.

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

Sidebar

Related Questions

I have some codes like this: cats = Category.objects.filter(is_featured=True) for cat in cats: entries
I have some codes like this: PrintWriter pw = new PrintWriter(new BufferedReader(....)); for(int i=0;
let's assume that I have some codes like this. What should I write there
I have some codes like this. Result 1 works fine, but result 2 displays
I have some codes as below #import <UIKit/UIKit.h> @interface ViewMoreSettingController : UIViewController < UITableViewDelegate,
I have been toying with some codes to solve this using a Levenberg-Marquardt solver
I have a large text file with 4-digit codes and some information about them
This is a class assignment. I had written some codes which I hope someone
UPDATE : A commenter told me to change some codes, this is the new
I'm a newbie in this vast world of programming. I've been given some codes

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.