简体   繁体   中英

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.

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.

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

paraDict =
{
email ="xyz@abc.co"
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];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM