问题描述
所以我正在构建一个应用程序,目的是检查签证状态。通过使用WebView,它可以填写表单,单击按钮并存储响应。问题是我的应用程序没有执行此操作,而是一次又一次地重复相同的过程,这不好,并且还触发了Drupal Honeypot的安全性。我猜它的问题与UI更新有关。我做了一些丑陋的解决方法,想更改它。如何仅对网页发出一次请求?预先谢谢你!
public class FourthActivity extends AppCompatActivity {
String aplicationNumber = "65708";
String aplicationNumberFake = "2";
String type = "ZM";
String year = "2019";
@Override
protected void onCreate(Bundle savedInstanceState) {
this.getSupportActionBar().hide();
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fourth);
Intent intent = getIntent();
final ArrayList<String> visaStatus = new ArrayList<String>(); //bad workaround
final WebView myWebview = findViewById(R.id.webview);
class MyJavaScriptInterface {
@JavascriptInterface
@SuppressWarnings("unused")
public void processHTML(final String html) {
myWebview.post(new Runnable() {
@Override public void run() {
visaStatus.add(html); //bad workaround
final TextView textVisaStatus = findViewById(R.id.textView);
textVisaStatus.setText(visaStatus.get(0)); //bad workaround
}
});
}
}
myWebview.getSettings().setJavaScriptEnabled(true);
myWebview.addJavascriptInterface(new MyJavaScriptInterface(),"HTMLOUT");
myWebview.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view,String url) {
myWebview.loadUrl("javascript:document.getElementById('edit-ioff-application-number').value = '" + aplicationNumber + "';void(0);");
myWebview.loadUrl("javascript:document.getElementById('edit-ioff-application-number-fake').value = '" + aplicationNumberFake + "';void(0);");
myWebview.loadUrl("javascript:document.getElementById('edit-ioff-application-code').value = '" + type + "';void(0);");
myWebview.loadUrl("javascript:document.getElementById('edit-ioff-application-year').value = '" + year + "';void(0);");
myWebview.loadUrl("javascript:document.getElementById('edit-submit-button').click();");
myWebview.loadUrl("javascript:window.HTMLOUT.processHTML(document.getElementsByClassName('alert alert-warning')[0].innerText);");
myWebview.loadUrl("javascript:window.HTMLOUT.processHTML(document.getElementsByClassName('alert alert-success')[0].innerText);");
myWebview.loadUrl("javascript:window.HTMLOUT.processHTML(document.getElementsByClassName('alert alert-danger')[0].innerText);");
}
});
myWebview.loadUrl("https://frs.gov.cz/ioff/application-status");
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)