Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. Alamofire.request(.GET, "url").authenticate(user: "", password: "").responseJSON() {
  2. (request, response, json, error) in
  3. println(error)
  4. println(json)
  5.  
  6. }
  7.  
  8. Optional(Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (Invalid value around character 0.) UserInfo=0x78e74b80 {NSDebugDescription=Invalid value around character 0.})
  9.  
  10. multipartFormData.appendBodyPart(data: image1Data, name: "file")
  11.  
  12. multipartFormData.appendBodyPart(data: image1Data, name: "file", fileName: "myImage.png", mimeType: "image/png")
  13.  
  14. Alamofire.request(.GET, "YOUR_URL")
  15. .validate()
  16. .responseString { response in
  17. print("Success: (response.result.isSuccess)")
  18. print("Response String: (response.result.value)")
  19. }
  20.  
  21. .validate(contentType: ["application/json"])
  22.  
  23. Alamofire.request(.GET, "url")
  24. .validate(contentType: ["application/json"])
  25. .authenticate(user: "", password: "")
  26. .responseJSON() { response in
  27. switch response.result {
  28. case .Success:
  29. print("It worked!")
  30. print(response.result.value)
  31. case .Failure(let error):
  32. print(error)
  33. }
  34. }
  35.  
  36. public func fetchDataFromServerUsingXWWWFormUrlencoded(parameter:NSDictionary, completionHandler: @escaping (_ result:NSDictionary) -> Void) -> Void {
  37.  
  38. let headers = ["Content-Type": "application/x-www-form-urlencoded"]
  39. let completeURL = "http://the_complete_url_here"
  40. Alamofire.request(completeURL, method: .post, parameters: (parameter as! Parameters), encoding: URLEncoding.default, headers: headers).responseJSON { response in
  41.  
  42. if let JSON = response.result.value {
  43. print("JSON: (JSON)") // your JSONResponse result
  44. completionHandler(JSON as! NSDictionary)
  45. }
  46. else {
  47. print(response.result.error!)
  48. }
  49. }
  50. }
  51.  
  52. let HOME_URL = "http://sitename.io"
  53. let BASE_URL = "http://sitename.io/api"
  54. let UPLOAD_URL = "http://sitename.io/api/user/upload"
  55.  
  56. let Auth_header: [String:String] = ["Accept":"application/json", "Content-Type" : "application/json", "Authorization":"Bearer MyToken"]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement