jav*_*ava 31 post android login http webview
我有一个由a组成的android应用程序,WebWiew我需要使用代码自动登录到站点.我尝试使用postUrl()它似乎工作......但只在某些网站上.
这是我正在使用的代码:
public class webviewActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebView webview = new WebView(this);
setContentView(webview);
WebSettings webSettings = webview.getSettings();
webSettings.setJavaScriptEnabled(true);
webview.setWebViewClient(new WebViewClient());
String postData = "login_email=myEmail@gmail.com&login_password=myPassword";
webview.postUrl("https://www.dropbox.com/login", EncodingUtils.getBytes(postData, "utf-8"));
}
}
Run Code Online (Sandbox Code Playgroud)
这个工程很大的dropbox.com,但其他网站如google.com,facebook.com等只需加载登录页面或给出错误(google.com给出了一个错误,说我需要启用Cookie).
现在我只是手工发布帖子数据; 查看站点的登录表单,并在我的代码中将名称/值字段放在postData中.在像google这样的网站上,登录表单有很多隐藏字段,我也一直在将它们添加到postData中.
如果有人能让我知道我做错了什么,请告诉我,我对此非常困惑.
小智 11
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebView webView = new WebView(this);
setContentView(webView);
String url = "http://example.com/somepage.php";
String postData = "postvar=value&postvar2=value2";
webView.postUrl(url, EncodingUtils.getBytes(postData, "base64"));
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
30770 次 |
| 最近记录: |