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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:55:31+00:00 2026-06-06T14:55:31+00:00

I wrote two code both are same Using NSURLConnection and Using AFNetworking. My NSURLConnection

  • 0

I wrote two code both are same

  1. Using NSURLConnection and
  2. Using AFNetworking.

My NSURLConnection code works fine but AFNetworking code don’t. Problem is I am getting JSON response from my NSURLConnection code but I am not getting JSON response from AFNetworking code but I am getting response code as 200. . I have tried all possible combination but still no luck. I dont know what is the problem. I wnat to use AFNetworking going forward so please someone help me. Thank you, — Amit

NSURLConnection:

- (IBAction)connectHandler:(UIButton *)sender {

//This is where we attempt to connect to the URL represented by self.labelHostURL
//along with exception handling
NSString *request_type = @"STARTUP";    
NSString *request_data = @"{\"lstCacheRefDt\":\"10/10/2010\",\"langCd\":\"en_US\",\"timeZn\":\"America/Chicago\",\"brndId\":\"WM\",\"prgmId\":\"WM0012\"}";
NSLog(@"Request: %@", request_data);

NSURL *url = [NSURL URLWithString:[ self.labelHostURL text ]];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
//NSData *requestData = [NSData dataWithBytes:[request_data UTF8String] length:[jsonRequest length]];

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

NSString* request_body = [NSString
                          stringWithFormat:@"request_type=%@&request_data=%@",
                          [request_type stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
                          [request_data stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

[request setHTTPBody:[request_body dataUsingEncoding:NSUTF8StringEncoding]];

[NSURLConnection connectionWithRequest:request delegate:self];    }

AFNetworking:

- (void) getHomeData {

NSURL *url = [[NSURL alloc] initWithString:@"https://localhost:8443/MNMMLMockService/mAccountsWeb/services/mnapp/rpc"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];

NSDictionary *homePostParams1 = [NSDictionary dictionaryWithObjectsAndKeys:
                                @"10/10/2010", @"lstCacheRefDt",
                                @"en_US", @"langCd",
                                @"America/Chicago", @"timeZn",
                                @"WM", @"brndId",
                                @"WM0012", @"prgmId", nil];

NSDictionary *homePostParams = [NSDictionary dictionaryWithObjectsAndKeys:@"STARTUP", @"request_type", homePostParams1,@"request_data", nil];

NSLog(@"Dic: %@", homePostParams);

NSMutableURLRequest *homeRequest = [httpClient requestWithMethod:@"POST" path:@"" parameters:homePostParams];
[homeRequest setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[homeRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];

AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:homeRequest
                                     success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
                                         NSLog(@"JSON %@", JSON);
                                         NSLog(@"operation StatusCode: %d", [response statusCode]);
                                     } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
                                         NSLog(@"Request Failed with Error: %@, %@", error, error.userInfo);
                                     }];
[operation start]; }
  • 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-06T14:55:32+00:00Added an answer on June 6, 2026 at 2:55 pm

    I use AFNetworking library but you seem to be missing some steps that I do. I usually subclass AFHTTPClient. Whether you subclass or not, make sure to call AFHTTPClient’s registerHTTPOperationClass method.

    For example in my AFHTTPClient subclass during the init process, I do (where self is AFHTTPClient instance) :

    [self registerHTTPOperationClass:[AFJSONRequestOperation class]];
    

    This will set the appropriate accept headers for you.

    For operations (all expect json responses), I do something like:

    AFHTTPRequestOperation *httpOperation = [httpClient HTTPRequestOperationWithRequest:request 
        success:^(AFHTTPRequestOperation *operation, id responseJSONObject) { // some logic}
        failure:^(AFHTTPRequestOperation *operation, NSError *error) { // some logic }];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two generic lists of type T. Both lists contain same type, and
I have two views which will both use the same Controller method: //webServiceController.cs //The
I have two computers. Both running WinXP SP2 (I don't really know ho similar
Can I write a hash code function for the following comparer logic? Two instances
I'm trying to write a piece of code that takes in a two digit
In Android 4.0 i put tab bar with two widget. in code i write
I wrote two small applications (a client and a server) to test UDP communication
I wrote two small java programs: a TCP client which sends many lines of
I wrote two methods with a void type parameter: procedure Method1(const MyVar; size: cardinal);
I wrote two methods in class Util: public static final <T> T[] copy1(T[] source)

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.