2017-05-08 127 views
0

Swift 3中的Alamofire 4請求總是失敗,並顯示500個狀態碼。我嘗試了Postman並且工作!使用django API和Alamofire請求失敗

看我的代碼:

func newUser(user: User) { 

    var urlRequest = URLRequest(url: URL(string: url + "/register")!) 
    urlRequest.httpMethod = "POST" 

    let parameters: Parameters = [ 
     "username": "\(user.name!)", 
     "email": "\(user.email!)", 
     "password": "(Kh=CE)4r)PC4}f?", 
     "profile": [ 
      "status": 0, 
      "level": 0, 
      "facebook_id": "\(user.fbId!)", 
      "facebook_token": "000", 
      "push_device_token": "000", 
      "photo": "\(user.photoUrl!)" 
     ] 
    ] 

    let headers: HTTPHeaders = ["Content-Type": "application/json"] 

    Alamofire.request(url+"/register", method: .post, parameters: parameters, encoding: JSONEncoding(options: []), headers: headers).response { response in 
     debugPrint(response) 
     print(response) 
    } 

} 

enter image description here

任何人都可以幫我嗎?

回答

0

我已經做了你所要完成的,我看到的唯一的區別是你的頭,試圖將其更改爲同一件事:

let headers = ["Authorization":)", password] 

Wireshark的還可以幫助你看到了500的確切原因錯誤。