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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:07:01+00:00 2026-06-01T15:07:01+00:00

Brief backstory, our previous developer used ASIHTTPRequest to make POST requests and retrieve data

  • 0

Brief backstory, our previous developer used ASIHTTPRequest to make POST requests and retrieve data from our webservice. For reasons unknown this portion of our app stopped working. Seemed like good enough time to future proof and go with AFNetworking. REST webservice runs on the CakePHP framework.

In short I am not receiving the request response string using AFNetworking.

I know the webservice works because I am able to successfully post data and receive the proper response using curl:
curl -d “data[Model][field0]=field0value&data[Model][field1]=field1value” https://example.com/api/class/function.plist

Per the previous developer’s instructions I came up with the following.

#import "AFHTTPRequestOperation.h"    

…

- (IBAction)loginButtonPressed {

    NSURL *url = [NSURL URLWithString:@"https://example.com/api/class/function.plist"];

    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];

    [request setHTTPMethod:@"POST"];

    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];

    [request setValue:[usernameTextField text] forHTTPHeaderField:@"data[User][email]"];

    [request setValue:[passwordTextField text] forHTTPHeaderField:@"data[User][password]"];

    AFHTTPRequestOperation *operation = [[[AFHTTPRequestOperation alloc] initWithRequest:request] autorelease];

    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {  

        NSLog(@"operation hasAcceptableStatusCode: %d", [operation.response statusCode]);

        NSLog(@"response string: %@ ", operation.responseString);

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

        NSLog(@"error: %@", operation.responseString);

    }];

    [operation start];

}

output:
operation hasAcceptableStatusCode: 200
response string: a blank plist file

attempted solution 1:
AFNetworking Post Request
the proposed solution uses a function of AFHTTPRequestOperation called operationWithRequest. However, when I attempt to use said solution I get a warning “Class method ‘+operationWithRequest:completion:’ not found (return type defaults to ‘id'”

attempted solution 2: NSURLConnection. output: I’m able to print the success log messaged but not the response string.
*update – returns blank plist.

NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
NSString *httpBodyData = @"data[User][email]=username@example.com&data[User][password]=awesomepassword";
[httpBodyData dataUsingEncoding:NSUTF8StringEncoding];
[req setHTTPMethod:@"POST"];
[req setHTTPBody:[NSData dataWithContentsOfFile:httpBodyData]];
NSHTTPURLResponse __autoreleasing *response;
NSError __autoreleasing *error;
[NSURLConnection sendSynchronousRequest:req returningResponse:&response error:&error];

// *update - returns blank plist
NSData *responseData = [NSURLConnection sendSynchronousRequest:req returningResponse:nil error:nil];
NSString *str = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(@"responseData %@",str);

if (error == nil && response.statusCode == 200) {
    // Process response
    NSLog(@"success");//returns success code of 200 but blank
    NSLog(@"resp %@", response );
} else {
    // Process error
    NSLog(@"error");
}
  • 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-01T15:07:03+00:00Added an answer on June 1, 2026 at 3:07 pm

    These are the essential (stripping out conditions I’ve made for my own use) lines that ended up satisfying my request to the web service. Thanks for the suggestions @8vius and @mattt !

    - (IBAction)loginButtonPressed {        
        NSURL *baseURL = [NSURL URLWithString:@"https://www.example.com/api/class"];
    
        //build normal NSMutableURLRequest objects
        //make sure to setHTTPMethod to "POST". 
        //from https://github.com/AFNetworking/AFNetworking
        AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:baseURL];
        [httpClient defaultValueForHeader:@"Accept"];
    
        NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
                                [usernameTextField text], kUsernameField, 
                                [passwordTextField text], kPasswordField, 
                                nil];
    
        NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST" 
              path:@"https://www.example.com/api/class/function" parameters:params];
    
        //Add your request object to an AFHTTPRequestOperation
        AFHTTPRequestOperation *operation = [[[AFHTTPRequestOperation alloc] 
                                          initWithRequest:request] autorelease];
    
        //"Why don't I get JSON / XML / Property List in my HTTP client callbacks?"
        //see: https://github.com/AFNetworking/AFNetworking/wiki/AFNetworking-FAQ
        //mattt's suggestion http://stackoverflow.com/a/9931815/1004227 -
        //-still didn't prevent me from receiving plist data
        //[httpClient registerHTTPOperationClass:
        //         [AFPropertyListParameterEncoding class]];
    
        [httpClient registerHTTPOperationClass:[AFHTTPRequestOperation class]];
    
        [operation setCompletionBlockWithSuccess:
          ^(AFHTTPRequestOperation *operation, 
          id responseObject) {
            NSString *response = [operation responseString];
            NSLog(@"response: [%@]",response);
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            NSLog(@"error: %@", [operation error]);
        }];
    
        //call start on your request operation
        [operation start];
        [httpClient release];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Brief question What command can I use to make my DataSet refresh it's connection
A brief preface: I'm in a game design class where our project for the
Brief question, beginner's work on Ruby/Rails. Here's my view: <h1>News</h1> <%= @posts.each do |post|
From some brief fiddling about, I find I get an error when overriding superclass
Brief Summary: We are using Tridion 2009 SP1, however we never used .NET templating,
Can Anyone give me brief detail about the resources used in UDP HolePunching as
brief update I might not even bother with a form to submit the data
I would like a brief and easy way to strip tags from an XHTML
Brief Background I'm investigating the potential of investing in Agile Toolkit for a future
Brief Idea about the flow : I have say minimum 1 and maximum 18

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.