Guest User

Untitled

a guest
Jan 22nd, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. let imageData = UIImageJPEGRepresentation(self.images.firstObject as! UIImage, 0.9)
  2.  
  3. let myBase64Data = imageData!.base64EncodedString(options: [])
  4.  
  5. let request = NSMutableURLRequest(url: URL(string: "http://www.example.com/members/mobileapi/uploadSingleFile/")!)
  6. request.httpMethod = "POST"
  7. let postString = "username=tiagotest&password=test&bpo_id=248522&encoded_string=(myBase64Data)&image_name=testFromIphone"
  8.  
  9. request.httpBody = postString.data(using: String.Encoding.utf8)
  10.  
  11. let task = URLSession.shared.dataTask(with: request as URLRequest) {
  12.  
  13. (data, response, error) in
  14. guard error == nil && data != nil else {
  15. print("error=(error)")
  16. return
  17. }
  18.  
  19. if let httpStatus = response as? HTTPURLResponse , httpStatus.statusCode != 200 {
  20. print("statusCode should be 200, but is (httpStatus.statusCode)")
  21. print("response = (response)")
  22. }
  23.  
  24. let responseString = String(data: data!, encoding: String.Encoding.utf8)
  25. print(responseString!)
  26. }
  27. task.resume()
  28.  
  29. <key>NSAppTransportSecurity</key>
  30. <dict>
  31. <key>NSAllowsArbitraryLoads</key>
  32. <true/>
  33. </dict>
Add Comment
Please, Sign In to add comment