Maninderjit Singh
Maninderjit Singh

Reputation: 1456

How to post API with parameters for HTTPS with AFNetworking iOS 9

I am hitting API with parameters with AFNetworking on HTTPS URL on iOS 9. My request is not sending the correct parameters to the server. I have put the keys in a plist and that doesn't work with the API.

Upvotes: 0

Views: 318

Answers (2)

Maninderjit Singh
Maninderjit Singh

Reputation: 1456

during Api Post i was sending dictionary as parameters which creates problem.Solution for Problem is given Below

paraDict =
{
email ="[email protected]"
password = "1234567"
}

make string of parameters 

 NSString *post = [NSString stringWithFormat:@"email=%@&password=%@"paraDict[@"email"],paraDict[@"password"]];

    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];


    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];


    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setHTTPBody:postData];

Upvotes: 0

BonanzaDriver
BonanzaDriver

Reputation: 6452

Remember, that if this is running on the simulator (Xcode 7/iOS9) you will probably need to add the NSAppTransportSecurity > NSAllowsArbitraryLoads == YES key/value into your info.plist for ANY communication to the outside world. This is the first requirement (simply making sure that you can hit an endpoint). Once that's done you'll need to use whatever API AFNetworking provides for your purposes.

Upvotes: 1

Related Questions