2016-05-27 2 views
1

私のUIWebViewにログインフォームを表示する方法を教えてもらえますか?webviewでウェブサイトからフォームのみを表示または読み込む方法は? - swift

http://webgiz.faqserv.com/webgiz/

(これは私のリンクが使用できなくなります場合はスクリーンショットです):

enter image description here

私ができない場合は、どのように私はスウィフトを使用して、私の変数でこのフォームを埋めることができますか?

今の私には、以下の姑息コードとして使用しています:

POST方法:例えば

WV1.stringByEvaluatingJavaScriptFromString("document.getElementById('username')‌​.value = '" + RA + "'") WV1.stringByEvaluatingJavaScriptFromString("document.getElementById('passwd').v‌​alue = '" + CPF + "'") WV1.stringByEvaluatingJavaScriptFromString("document.getElementById('btnlogin')‌​.click()")

+0

助けが必要な場合は、あなたのカスタムUIWebViewについてのode .. –

+0

すべての権利、ありがとう。このウェブページのテキストフィールドにテキスト(var)を入力するにはどうすればよいですか? –

答えて

0

あなたはこのJoomlaのポータルにログインし、残りの完全なパラメータを検出する必要があります。 http://webgiz.faqserv.com/webgiz/index.php?option=com_aixgen&username=test&password=test&userType=A&instituicao=0

@IBOutlet weak var usernameTextField: UITextField! 
// `passwordTextField.secureTextEntry = true` 
@IBOutlet weak var passwordTextField: UITextField! 
@IBOutlet weak var webView: UIWebView! 

... 

@IBAction func signIn(sender: AnyObject) { 
    var url = NSURL(string: "http://webgiz.faqserv.com/webgiz/index.php") 
    var request = NSMutableURLRequest(URL: url!) 
    request.HTTPMethod = "POST" 

    // Get the user's credentials from the `UITextField`s 
    var username: String = usernameTextField.text 
    var password: String = passwordTextField.text 

    // Concatenating everything together 
    var userCredentials: String = "username=\(username)&passwd=\(password)&userType=A&instituicao=0" // add all parameters needed 
    var bodyData: String = "\(userCredentials)" 

    // Encode the bodyData string into a 
    request.HTTPBody = bodyData.dataUsingEncoding(NSUTF8StringEncoding) 

    // load the UIWebView `webView` with this request 
    webView.loadRequest(request) 
} 
+0

もう一度ありがとうございます!私はパラメータを見つけることを試みる。私は趣味をしています。今のところ私は以下の緩和的なコードとして使用しています: 'WV1.stringByEvaluatingJavaScriptFromString(" document.getElementById( 'username')。value = '"+ RA +"' ");' 'WV1.stringByEvaluatingJavaScriptFromString(" document.getElementById ( 'passwd')。'WV1.stringByEvaluatingJavaScriptFromString(" document.getElementById( 'btnlogin')。クリック() "); ' –

+0

あなたがアプローチする方法意味をなさないかもしれない。ユーザーがユーザー名とパスワードを正しく挿入すると、webviewのリダイレクトはすぐにURLアドレスをサイトの内部ページにリダイレクトします。受動的なリスニング方法です。この場合には、ウェブビューのログインボタン「Entrar」が押されたときにそれを傍受して何をするかを選択するのが最善の方法です。 –

関連する問題