2017-06-22 66 views
4

我無法登錄我的應用程序,它使用Oath-2,並獲取unsupported_grant_type錯誤。我使用Alamofire POST登錄數據,但無法成功。在我做錯了嗎?我無法解決問題。獲取錯誤不支持授予類型?

FUNC sendFeedback()

func sendFeedback(){ 


     let parameters = [ 

      "UserName": username_textfield.text! as String, 
      "Password": password_textfield.text! as String, 
      "grant_type": "Password" as String, 
        ] 


     Alamofire.upload(multipartFormData: { multipartFormData in 

      for (key, value) in parameters { 
       multipartFormData.append((value.data(using: .utf8))!, withName: key) 
      }}, to: "http://192.168.100.5:84/Token", method: .post, headers: ["Authorization": "auth_token"], 
       encodingCompletion: { encodingResult in 
        switch encodingResult { 
        case .success(let upload, _, _): 
         upload.response { [weak self] response in 
          guard self != nil else { 
           return 
          } 
          debugPrint(response) 
//       self?.view.hideToastActivity() 
          self?.view.makeToast(message: "Send Successfull. !!!") 

         } 
         upload.uploadProgress(queue: DispatchQueue(label: "uploadQueue"), closure: { (progress) in 


         }) 
        case .failure(let encodingError): 
         print("errorss:\(encodingError)") 
        } 
     }) 

    } 

我得到400.How的狀態代碼這個問題要解決?

+0

嘗試「密碼」(小寫) RFC 6749「這個規範定義了四種類型的補助 - 授權碼,含蓄,資源所有者....除非否則注意,所有的協議參數名稱和值是區分大小寫的「 – jwilleke

+0

它不工作將密碼更改爲小寫 –

回答

3

試試這個,這可能會幫助你

let headers = [ 
      "Content-Type": "application/x-www-form-urlencoded" 
     ] 
     let parameters = [ 

      "UserName": username_textfield.text! as String, 
      "Password": password_textfield.text! as String, 
      "grant_type": "password", 
        ] 
     //  let url = NSURL(string: "http://192.168.100.5:84/Token")! 
     Alamofire.request("http://192.168.100.5:84/Token", method: .post, parameters: parameters, encoding: URLEncoding.httpBody, headers: headers).responseJSON { (response:DataResponse<Any>) in 

      switch(response.result) { 

      case .success(_): 
       if response.result.value != nil{ 
//     print(response.result.value ??) 
        let statusCode = (response.response?.statusCode)! 
        print("...HTTP code: \(statusCode)") 
       } 
       break 

      case .failure(_): 
//    print(response.result.error ??) 
       break 

      } 
     } 
+0

是的,它的工作原理謝謝。快樂編碼!!! –

+0

@BikeshThakur :-) – seon

相關問題