ios - webview获取title - 获取错误不支持授予类型?



webview document title (1)

试试这个 ,这可能对你有帮助

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

           }
       }

我不能在我的应用程序中使用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的状态代码。如何解决这个问题?





alamofire