Mohamed Diaa Mohamed Diaa - 6 months ago 231
Swift Question

How to use Alamofire to send Form-data as in Postman

I want to make similar ALamofire request as Postman request shown in screenshot

I ended up that POST + Alamofire UPload + appendBodyPart(#stream: NSInputStream, length: UInt64, headers: [String: String])

will be the Answer but did not find clear example how to implement it ?

http://cocoadocs.org/docsets/Alamofire/1.3.1/Classes/MultipartFormData.html#/s:FC9Alamofire17MultipartFormData14appendBodyPartFS0_FT6streamCSo13NSInputStream6lengthVSs6UInt647headersGVSs10DictionarySSSS__T_

Postman screenshot

Answer

Your simple POST request with Alamofire should be like this

    Alamofire.request(.POST, "http:/request.example.com", parameters: ["foo": "bar","key_1":"value_1"])
     .response { request, response, data, error in
          println(request)
          println(response)
          println(error)
      }

You can use .responseJSON , .responseString according to your response