Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Alamofire.request(.GET, "url").authenticate(user: "", password: "").responseJSON() {
- (request, response, json, error) in
- println(error)
- println(json)
- }
- 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.})
- multipartFormData.appendBodyPart(data: image1Data, name: "file")
- multipartFormData.appendBodyPart(data: image1Data, name: "file", fileName: "myImage.png", mimeType: "image/png")
- Alamofire.request(.GET, "YOUR_URL")
- .validate()
- .responseString { response in
- print("Success: (response.result.isSuccess)")
- print("Response String: (response.result.value)")
- }
- .validate(contentType: ["application/json"])
- Alamofire.request(.GET, "url")
- .validate(contentType: ["application/json"])
- .authenticate(user: "", password: "")
- .responseJSON() { response in
- switch response.result {
- case .Success:
- print("It worked!")
- print(response.result.value)
- case .Failure(let error):
- print(error)
- }
- }
- public func fetchDataFromServerUsingXWWWFormUrlencoded(parameter:NSDictionary, completionHandler: @escaping (_ result:NSDictionary) -> Void) -> Void {
- let headers = ["Content-Type": "application/x-www-form-urlencoded"]
- let completeURL = "http://the_complete_url_here"
- Alamofire.request(completeURL, method: .post, parameters: (parameter as! Parameters), encoding: URLEncoding.default, headers: headers).responseJSON { response in
- if let JSON = response.result.value {
- print("JSON: (JSON)") // your JSONResponse result
- completionHandler(JSON as! NSDictionary)
- }
- else {
- print(response.result.error!)
- }
- }
- }
- let HOME_URL = "http://sitename.io"
- let BASE_URL = "http://sitename.io/api"
- let UPLOAD_URL = "http://sitename.io/api/user/upload"
- 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