我需要登录并发布用户ID,并将单词传递到Web视图中。 谁能帮我!预先感谢。
如何在Web视图中显示所需的内容。我需要在Web视图中获取必需的内容才能发布登录数据
public class MainActivity extends AppCompatActivity {
EditText login_user,login_password;
Button login_button;
String uName,uPwd,data;
WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
login_user=(EditText)findViewById(R.id.userName);
login_password=(EditText)findViewById(R.id.passWord);
login_button=(Button)findViewById(R.id.loginButton);
webView=(WebView)findViewById(R.id.webView);
login_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try{
getText();
}catch(Exception e){
e.printStackTrace();
}
}
});
}
private void getText() {
uName = login_user.getText().toString();
uPwd = login_password.getText().toString();
WebView webview = new WebView(this);
setContentView(webview);
String url = "website url";
String postData = null;
try {
postData = "username=" + URLEncoder.encode(uName, "UTF-8") + "&password=" + URLEncoder.encode(uPwd, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
webview.postUrl(url,postData.getBytes());
}
}
答案 0 :(得分:0)
您可以尝试以下操作:-
String postData = "username=abc&password=236";
webview.postUrl(
"website url/exampleURL",
EncodingUtils.getBytes(postData, "BASE64"));
,并检查此链接:- 1)How to post data for WebView android