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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:16:47+00:00 2026-06-07T02:16:47+00:00

I am trying to send a POST request to a server using AFNetworking, and

  • 0

I am trying to send a POST request to a server using AFNetworking, and everything seems to be working, i.e. the application is successfully pinging the server. However, the parameter values that it is sending are blank when it reaches the server even though after stepping through my code below using the debugger, the values appear to be being passed successfully. Any help on this would be greatly appreciated.

APIClient.m

#import "APIClient.h"
#import "AFJSONRequestOperation.h"

// Removed URL for privacy purposes.
static NSString * const kAPIBaseURLString = @"string goes here";

@implementation APIClient

+ (APIClient *)sharedClient {
    static APIClient *_sharedClient;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _sharedClient = [[APIClient alloc] initWithBaseURL:[NSURL URLWithString:kAPIBaseURLString]];
    });

    return _sharedClient;
}

- (id)initWithBaseURL:(NSURL *)url {
    self = [super initWithBaseURL:url];
    if (self) {
        [self registerHTTPOperationClass:[AFJSONRequestOperation class]];

        // Accept HTTP Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1
        [self setDefaultHeader:@"Accept" value:@"application/json"];
    }

    return self;
}

@end

Login Method in LoginBrain.m

- (void)loginUsingEmail:(NSString *)email andPassword:(NSString *)password withBlock:(void (^)(NSDictionary *loginResults))block {
    self.email = email;
    self.password = password;

    // Removed path for privacy purposes
    [[APIClient sharedClient] postPath:@"insert path here" parameters:[NSDictionary dictionaryWithObjectsAndKeys:email, @"uname", password, @"pw", nil] success:^(AFHTTPRequestOperation *operation, id responseJSON) {
        if (block) {
            block(responseJSON);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"Error: %@", error);

        if (block) {
            block(nil);
        }
    }];

    // Store user data in app?
}

Login Called Method in LoginViewController.m

- (IBAction)loginPressed {
    [self.loginProgressIndicator startAnimating];
    NSString *email = self.emailTextField.text;
    NSString *password = self.passwordTextField.text;

    [self.brain loginUsingEmail:email andPassword:password withBlock:^(NSDictionary *loginResults) {
        [self.loginProgressIndicator stopAnimating];
        [self.delegate uloopLoginViewController:self didLoginUserWithEmail:email andPassword:password];
    }];
}

UPDATE

I tried changing the parameterEncoding as recommended here, but it did not fix the problem.

SECOND UPDATE

Here is the PHP code from the server side that is accessing the POST data. This was written by a co-worker of mine, as I don’t do anything on the server side and am very unfamiliar with how it works.

header('Content-type: application/json');
$username = $_POST['uname'];
$pw = $_POST['pw'];

The server code is pretty straight forward. He has some sort of log script that checks to see what the variable values are, and he says that the client is hitting the server, but the variable values are blank.

THIRD UPDATE

This is a dump of the HTTP request by generating a print_r of the $_REQUEST variable:

Array ( [sid] => FwAqvZrfckw )

And here is a dump of the $_POST variable. As you can see, it’s completely blank:

Array ( )

FOURTH UPDATE

I used Wireshark to capture the packet before it’s being sent to the server, and everything appears to be in order:

Accept: application/json
Content-Type: application/x-www-form-urlencoded; charset=utf-8

And the POST parameters were all there as well. We also created a test file on the server side and just did a test POST to make sure that the code there is working, and it is.

  • 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-07T02:16:48+00:00Added an answer on June 7, 2026 at 2:16 am

    I don’t see anything in particular that would cause a problem here but I’ll start off by giving you the steps I used to solve a similar problem.

    To start, checkout the tool, Charles, which is a Debugging Web Proxy that will intercept the response from the server and should give you a more clear idea of what’s going wrong. There’s a 30 day free trial and it really helped me pick out the little bugs. To use it, press the sequence button and filter the results via your server url. From there you can see the request and response sent and received from the server. If the following doesn’t fix your problem, post the request and response that Charles spits out.

    Fix wise, try adding [[APIClient sharedClient] setParameterEncoding:AFJSONParameterEncoding] right before you send the POST request. It looks like yall are using JSON as the server-side format.

    So in loginUsingEmail:

    self.email = email;
    self.password = password;
    
    [[APIClient sharedClient] setParameterEncoding:AFJSONParameterEncoding];
    
    [[APIClient sharedClient] postPath:@"insert path here" parameters:[NSDictionary dictionaryWithObjectsAndKeys:email, @"uname", password, @"pw", nil] success:^(AFHTTPRequestOperation *operation, id responseJSON) {
        if (block) {
            block(responseJSON);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"Error: %@", error);
    
        if (block) {
            block(nil);
        }
    }];
    
    // Store user data in app?
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to send a POST request to my server, everything seems to
I need to send a POST request using java. The server i am trying
I am trying to send data to a web server using a post, this
I'm trying to send a cURL request from a Windows Server 2008 machine using
I am trying to send a POST request to a rails scaffold controller which
I'm trying to send a post request to Parse: https://parse.com/docs/rest#objects-creating . Can't get it
I have a problem when trying to send a POST request. The sending method
I am receiving a NullPointerException when trying to send a POST request to a
Trying to find a way to send a POST HTTPS request from Python to
I'm trying to send post using API feed. I set fields: message , link

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.