How to call REST API with form data using POST method?
<p>How to call Rest Api with form data using post method in swift iOS? </p>

<p>I want similar code for Swift to hit Rest Api with formed data using <strong>"Post"</strong> Method:</p>

<pre><code>NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
    NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil];

    NSString *encodedUrl = [[NSString stringWithFormat:@"%@%@", self.BaseUrl, strMethodName]stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];

    NSURL *serverUrl = [NSURL URLWithString:encodedUrl];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:serverUrl cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];

    NSError *error = nil;


    NSMutableString *body = [NSMutableString string];

    for (NSString *key in requestDict) {

        NSString *val = [requestDict objectForKey:key];

        if ([body length]){

            [body appendString:@"&amp;"];

        }

        [body appendFormat:@"%s=%s", [[key description] UTF8String], [[val description] UTF8String]];

    }

   NSMutableData *postData = (NSMutableData *)[body dataUsingEncoding:NSUTF8StringEncoding];
    NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[postData length]];
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    //    [request setValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [request setValue:@"application/x-www-form-urlencoded charset=utf-8" forHTTPHeaderField:@"Content-Type"];
</code></pre>