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 8899815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:57:00+00:00 2026-06-15T00:57:00+00:00

I was wondering if anyone could point out why I’m not able to capture

  • 0

I was wondering if anyone could point out why I’m not able to capture a web reply. My NSLog shows that my [NSMutableData receivedData] has a length of 0 the entire run of the connection. The script that I hit when I click my login button returns a string. My NSLog result is pasted below, and after that I’ve pasted both the .h and .m files that I have.

NSLog Result

2012-11-28 23:35:22.083 [12548:c07] Clicked on button_login
2012-11-28 23:35:22.090 [12548:c07] theConnection is succesful
2012-11-28 23:35:22.289 [12548:c07] didReceiveResponse
2012-11-28 23:35:22.290 [12548:c07] didReceiveData
2012-11-28 23:35:22.290 [12548:c07] 0
2012-11-28 23:35:22.290 [12548:c07] connectionDidFinishLoading
2012-11-28 23:35:22.290 [12548:c07] 0

ViewController.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

// Create an Action for the button.
- (IBAction)button_login:(id)sender;

// Add property declaration.
@property (nonatomic,assign) NSMutableData *receivedData;

@end

ViewController.m

#import ViewController.h

@interface ViewController ()
@end

@implementation ViewController

@synthesize receivedData;

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    NSLog(@"didReceiveResponse");    
    [receivedData setLength:0];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {    
    NSLog(@"didReceiveData");    
    [receivedData appendData:data];
    NSLog(@"%d",[receivedData length]);
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {    
    NSLog(@"connectionDidFinishLoading");
    NSLog(@"%d",[receivedData length]);
}

- (IBAction)button_login:(id)sender {

    NSLog(@"Clicked on button_login");    
    NSString *loginScriptURL = [NSString stringWithFormat:@"http://www.website.com/app/scripts/login.php?"];

    NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:loginScriptURL]];

    NSString *postString = [NSString stringWithFormat:@"&paramUsername=user&paramPassword=pass"];
    NSData *postData = [postString dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

    [theRequest setHTTPMethod:@"POST"];
    [theRequest setHTTPBody:postData];

    // Create the actual connection using the request.
    NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

    // Capture the response
    if (theConnection) {        
        NSLog(@"theConnection is succesful");        
    } else {        
        NSLog(@"theConnection failed");
    }
}
@end
  • 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-15T00:57:01+00:00Added an answer on June 15, 2026 at 12:57 am

    The issue is you are not initializing the receivedData instance. Just change your property like:

    @property (nonatomic, retain) NSMutableData *receivedData;
    

    And change the methods like:

    - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
    {
        NSLog(@"didReceiveResponse");    
        [self.receivedData setLength:0];
    }
    
    - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
    {    
        NSLog(@"didReceiveData");    
        [self.receivedData appendData:data];
        NSLog(@"%d",[receivedData length]);
    }
    
    - (void)connectionDidFinishLoading:(NSURLConnection *)connection
    {    
        NSLog(@"connectionDidFinishLoading");
        NSLog(@"%d",[receivedData length]);
    }
    
    - (IBAction)button_login:(id)sender
    {
    
        NSLog(@"Clicked on button_login");    
        NSString *loginScriptURL = [NSString stringWithFormat:@"http://www.website.com/app/scripts/login.php?"];
    
        NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:loginScriptURL]];
    
        NSString *postString = [NSString stringWithFormat:@"&paramUsername=user&paramPassword=pass"];
        NSData *postData = [postString dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
    
        [theRequest setHTTPMethod:@"POST"];
        [theRequest setHTTPBody:postData];
    
        // Create the actual connection using the request.
        NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
    
        // Capture the response
        if (theConnection)
        {        
            NSLog(@"theConnection is succesful");  
            self.receivedData = [NSMutableData data];      
        } else
        {        
            NSLog(@"theConnection failed");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering if anyone could point out a cleaner better way to write
I was wondering if anyone could help me out, or point me in the
I was wondering if anyone could give me an example or point me to
I was wondering if anyone could point to an Open Source date utility class
I was wondering if anyone could point me to any resources or overviews as
So I was wondering if anyone knew how, or could point me in the
I was wondering if anyone could point me to a very very large dictionary
i'm relatively new to this and was wondering if anyone could point me in
I was wondering whether anyone could assist me. When the user clicks the menu
I was wondering if anyone could instruct as how to replace hyperlinks with their

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.