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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:58:21+00:00 2026-05-25T06:58:21+00:00

I have found a lot of good advice on stackoverflow about setting up a

  • 0

I have found a lot of good advice on stackoverflow about setting up a HTTP POST request to my server. I have followed a lot of examples. I have setup a quick test in a project to atempt to send a POST request and retrieve some data from the server. Here is my code from the ViewController.h I have setup:

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController {
IBOutlet UILabel *label;
NSString *moviePost;
NSMutableData *httpResponse;
    NSURLConnection *connection;

}

@property (nonatomic, retain) NSString *moviePost;
@property (nonatomic, retain) NSURLConnection *connection;

@end

And code from my ViewController.m

#import "ViewController.h"
#import <YAJLiOS/YAJL.h>

@implementation ViewController

@synthesize moviePost;
@synthesize connection;

- (void) viewDidLoad {
[super viewDidLoad];

    NSArray *fields = [[NSArray alloc] initWithObjects:@"rating",@"genre",@"plotoutline",@"runtime",@"director",@"writer",@"mpaa",@"year",@"studio", nil];

NSDictionary *params = [[NSDictionary alloc] initWithObjectsAndKeys:
                        fields,@"fields",
                        nil];
[fields release];
NSDictionary *tempPost = [[NSDictionary alloc] initWithObjectsAndKeys:
                          @"2.0", @"jsonrpc",
                          @"VideoLibrary.GetMovies", @"method",
                          @"1", @"id",
                          params, @"params",
                          nil];
[params release];
moviePost = [tempPost yajl_JSONString];
[tempPost release];


NSLog(@"Going to post: %@\n\n", moviePost);

NSString *url = [NSString stringWithFormat:@"http://192.168.1.133:8080/jsonrpc"];

NSMutableString* requestURL = [[NSMutableString alloc] init];
    [requestURL appendString:url];

    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString: [NSString stringWithString:requestURL]]];

NSData *requestData = [NSData dataWithBytes: [moviePost UTF8String] length: [moviePost length]];

    [request setHTTPMethod: @"POST"];
    [request setValue:@"text/plain" forHTTPHeaderField:@"content-type"];
    [request setHTTPBody: requestData];

    connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
    [request release];

}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[httpResponse setLength:0];
}

// Called when data has been received
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[httpResponse appendData:data];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    NSString* responseString = [[NSString alloc] initWithData:httpResponse encoding:NSUTF8StringEncoding];

    // Do something with the response
    NSLog(@"Response: %@", responseString);

    [responseString release];
    [connection release];
    [httpResponse release];
}

- (void)dealloc {
    [moviePost release];
    [super dealloc];
}

Most of the code comes from examples I have found. It does work to send a POST request to the server, and the server does respond with data. I have proven this by doing a packet capture between the test device and the server. The correct request is getting sent and the correct response is being sent back. I am not getting any issues when I run the app. I have run through the Analyzer and I do not get any issues.

The problem I have is that I am not able to get the response to print in the NSLog. When
- (void)connectionDidFinishLoading:(NSURLConnection *)connection runs it does show a line of Response: in the NSLog, but that is all I get.

Is there something I am missing? I am new to objective-c and xcode. Any help is appreciated.

  • 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-25T06:58:22+00:00Added an answer on May 25, 2026 at 6:58 am

    albertamg nailed it in a comment.

    you need to alloc and init your NSMutableData *httpResponse unless you’ve done that somewhere else and not shown it in the above code.

    You should add this in your viewDidLoad method

    httpResponse = [[NSMutableData alloc] init];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have found a lot of topics about stress-testing web application. My goals are
I have found numerous examples on uploading a file to a web server via
Good day, I found a lot of topics about that, but, without a proper
I have found a lot of information on using UIImagePickerController to let the user
I've scored the internet for sources and have found a lot of useful information,
I have googled a lot on this and i have found integrations of Linkedin
I know try catch have been discussed a lot but I haven’t found a
I am new to SCOM, but I have read a lot about it and
After a lot of good comment about IDEA, I decided to give it a
I have found myself designing a language for fun that is a cross between

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.