title: Alamofire post request with body in swift
body: <p>I'm trying to make post request with alamofire with body, but I keep having this error code "Message: An error has occurred."
  I run the same api in obj-c and afnetworking, all works fine. Am I using the wrong way to make parameters?</p>
  
  <pre><code>let parameters: [String: Any] = ["ID": "aaaa@test.com", "PW": "12345", "LoginType": "IDPW", "PushKey": "ios"]
  Alamofire.request(loginApi, method: .post, parameters: parameters, encoding: JSONEncoding.default)
              .responseJSON { response in
                  print(response)
          }
  </code></pre>
  
  <p>Body i send using Objective-C &amp; function</p>
  
  <pre><code>     NSDictionary *parameters = @{
                               @"LoginType": @"IDPW",
                               @"ID": @"aaaa@test.com",
                               @"PW": @"12345",
                               @"PushKey":  @"ios"
                               };
       - (void) AsyncHttpRequestWithMethod:(NSString * _Nonnull)method
                        URLString:(NSString * _Nonnull)URLString
                       parameters:(NSDictionary * _Nullable)parameters
                          headers:(NSDictionary * _Nullable)headers
                   uploadProgress:(nullable void (^)(NSProgress * _Nullable uploadProgress)) uploadProgressBlock
                 downloadProgress:(nullable void (^)(NSProgress * _Nullable downloadProgress)) downloadProgressBlock
                completionHandler:(nullable void (^)(NSURLResponse * _Nullable response, id _Nullable responseObject,  NSError * _Nullable error))completionHandler {
  
  AFURLSessionManager *manager = [[AFURLSessionManager alloc]initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
  
  NSMutableURLRequest *req = [[AFHTTPRequestSerializer serializer] requestWithMethod:method URLString:URLString parameters:parameters error:nil];
  
  req.timeoutInterval = intTimeInterval;
  
  if (headers &amp;&amp; headers.count &gt; 0) {
      NSArray *keys = headers.allKeys;
      for (int i = 0; i &lt; headers.count; i ++) {
          [req addValue:headers[keys[i]] forHTTPHeaderField:keys[i]];
      }
  }
  
  [[manager dataTaskWithRequest:req uploadProgress:^(NSProgress * _Nonnull uploadProgress) {
      if (uploadProgressBlock) uploadProgressBlock(uploadProgress);
  } downloadProgress:^(NSProgress * _Nonnull downloadProgress) {
      if (downloadProgressBlock) downloadProgressBlock(downloadProgress);
  } completionHandler:^(NSURLResponse * _Nonnull response, id  _Nullable responseObject, NSError * _Nullable error) {
  
      NSLog(@"completionHandler......");
  
      completionHandler(response, responseObject, error);
  }] resume];
  </code></pre>
  
  <p>}</p>