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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:05:15+00:00 2026-05-31T02:05:15+00:00

I’ve looked through SO and Google and haven’t found a similiar issue to this.

  • 0

I’ve looked through SO and Google and haven’t found a similiar issue to this. I feel like the answer is staring me in the face and I just need another set of eyes.

I’m using AFNetworking to connect to the Stripe.com API. Specifically I’m using AFHTTPClient postPath to send data to an endpoint, charges. Stripe requires the request to be encoded as application/x-www-form-urlencoded so I can’t use JSON encoding.

The problem I’m running into is that I have a Charge object and a Card object. Card is a property on Charge and I convert both Charge and Card to NSDictionary’s (Card is an dictionary inside of the Charge dictionary) and then pass them in as the parameters on the request like so:

NSDictionary *parameters = [ChargeRequest convertToDictionary:request];

[[StripeAPIClient sharedClient] postPath:@"charges" parameters:parameters 
success:^(AFHTTPRequestOperation *operation, id responseObject) 
{        
    NSLog(@"Response: %@", responseObject);
} 
failure:^(AFHTTPRequestOperation *operation, NSError *error) {        
    NSLog(@"Error: %@", [error localizedDescription]);
    NSLog(@"Response: %@", operation.responseString);
}];

When I do this, with AFHttpClient’s parameterEncoding property set to AFFormURLParameterEncoding, Stripe returns this error:

"error": {
    "message": "Invalid token id: {\n    \"exp_month\" = 10;\n    \"exp_year\" = 2016;\n      number = 4242111111111111;\n}",
    "type": "invalid_request_error"
}

The values in the error are specifically the key/values on the Card object after converting it. Here is the code I use for the conversion:

   return [[NSDictionary alloc] initWithObjectsAndKeys:request.number, @"number", [NSNumber numberWithInt:10], @"exp_month", [NSNumber numberWithInt:2016], @"exp_year", nil];

Any advice on what do to get rid of the invalid tokens being put in this NSDictionary? Am I focusing on the wrong thing?

Thanks!

  • 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-31T02:05:16+00:00Added an answer on May 31, 2026 at 2:05 am

    AFNetworking support only AFFormURLParameterEncoding with 1 level of parameters.

    I’m writing a fix for that

    replace AFQueryStringFromParametersWithEncoding implementation in AFHTTPClient by

    extern NSArray * AFQueryParametersFromParametersAtBaseKeyWithEncoding(id parameters, NSString *baseKey, NSStringEncoding encoding);
    extern NSArray * AFQueryParametersFromParametersDictionaryAtBaseKeyWithEncoding(NSDictionary *parameters, NSString *baseKey, NSStringEncoding encoding);
    extern NSArray * AFQueryParametersFromParametersArrayAtBaseKeyWithEncoding(NSArray *parameters, NSString *baseKey, NSStringEncoding encoding);
    extern NSArray * AFQueryStringComponentFromParameterAtBaseKeyWithEncoding(id parameter, NSString *key, NSStringEncoding encoding);
    
    NSString * AFQueryStringFromParametersWithEncoding(NSDictionary *parameters, NSStringEncoding encoding) {
        NSMutableArray *mutableParameterComponents = [NSMutableArray array];
        [mutableParameterComponents addObjectsFromArray:AFQueryParametersFromParametersAtBaseKeyWithEncoding(parameters,nil,encoding)];   
        return [mutableParameterComponents componentsJoinedByString:@"&"];
    }
    
    NSArray * AFQueryParametersFromParametersAtBaseKeyWithEncoding(id parameters, NSString *baseKey, NSStringEncoding encoding)
    {
        NSMutableArray *mutableParameterComponents = [NSMutableArray array];
    
        if([parameters isKindOfClass:[NSDictionary class]]) {
            [mutableParameterComponents addObjectsFromArray:AFQueryParametersFromParametersDictionaryAtBaseKeyWithEncoding(parameters,baseKey,encoding)];
        }
        else if([parameters isKindOfClass:[NSArray class]]) {
            [mutableParameterComponents addObjectsFromArray:AFQueryParametersFromParametersArrayAtBaseKeyWithEncoding(parameters,baseKey,encoding)];
        }
        else {
            [mutableParameterComponents addObject:AFQueryStringComponentFromParameterAtBaseKeyWithEncoding(parameters,baseKey,encoding)];
        } 
    
        return mutableParameterComponents;
    }
    
    NSArray * AFQueryParametersFromParametersDictionaryAtBaseKeyWithEncoding(NSDictionary *parameters, NSString *baseKey, NSStringEncoding encoding)
    {
        NSMutableArray *mutableParameterComponents = [NSMutableArray array];
    
        id key = nil;
    
        NSEnumerator *enumerator = [parameters keyEnumerator];
        while ((key = [enumerator nextObject])) {
            NSString *newKey = baseKey?[NSString stringWithFormat:@"%@[%@]",baseKey,key]:key;
            [mutableParameterComponents addObjectsFromArray:AFQueryParametersFromParametersAtBaseKeyWithEncoding([parameters valueForKey:key],newKey,encoding)];
        }
    
        return mutableParameterComponents;
    }
    
    NSArray * AFQueryParametersFromParametersArrayAtBaseKeyWithEncoding(NSArray *parameters, NSString *baseKey, NSStringEncoding encoding)
    {
        NSMutableArray *mutableParameterComponents = [NSMutableArray array];
    
        for (id value in parameters) {
            NSString* newKey = [NSString stringWithFormat:@"%@[]",newKey];
            [mutableParameterComponents addObjectsFromArray:AFQueryParametersFromParametersAtBaseKeyWithEncoding(value,newKey,encoding)];
        }
    
        return mutableParameterComponents;
    }
    
    NSArray * AFQueryStringComponentFromParameterAtBaseKeyWithEncoding(id parameter, NSString *key, NSStringEncoding encoding)
    {
        return [NSString stringWithFormat:@"%@=%@", AFURLEncodedStringFromStringWithEncoding([key description], encoding), AFURLEncodedStringFromStringWithEncoding([parameter description], encoding)];
    }
    

    I’m just writing the same code for multipart requests and submit a pull request to AFNetworking

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.