Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Alamofire
- let parameters: Parameters = [
- "str_param": "str value",
- "num_param": 0,
- "nested": [
- "nested_param": "value"
- ]
- ]
- Alamofire.request(url,
- method: .post,
- parameters: parameters,
- encoding: JSONEncoding.default,
- headers: headers)
- .authenticate(user: "user", password: "password")
- .responseJSON { response in
- if
- let json = response.result.value as? [String: Any],
- let prop1 = json["prop1"] as? String
- {
- debugPrint(prop1)
- }
- debugPrint(response)
- }
- func appendMultipartFormData(multipartFormData: MultipartFormData, element: [String: Any]) {
- switch element["value"] {
- case let image as UIImage:
- var imageData: Data
- var mimeType: String
- if element["extension"] as! String == "jpg" {
- print(element["extension"] as! String)
- imageData = UIImageJPEGRepresentation(image, 1.0)!
- mimeType = "jpeg"
- } else {
- imageData = UIImagePNGRepresentation(image)!
- mimeType = "png"
- }
- multipartFormData.append(
- imageData,
- withName: element["key"] as! String,
- fileName: element["name"] as! String,
- mimeType: mimeType
- )
- default:
- let value = element["value"] as! String
- multipartFormData.append((value.data(using: .utf8))!, withName: element["key"] as! String)
- break
- }
- func uploaldMultipartProcess(upload: UploadRequest, completeNotificationName: NSNotification.Name) {
- upload
- .uploadProgress(closure: { (progress) in
- print("Upload Progress: (progress.fractionCompleted)")
- })
- .validate(statusCode: 200..<300)
- .validate(contentType: ["application/json"])
- .responseJSON { (response: DataResponse<Any>) in
- let statusCode = response.response?.statusCode
- print("Success: (response.result.isSuccess)")
- print("Status code: (String(describing: statusCode))")
- }
Add Comment
Please, Sign In to add comment