如何发送与code POST数据在Android的WebView [英] How to send POST data with code in an android webview
问题描述
我有一个Android应用程序,它由一个 WebWiew
的,我需要自动使用code登录到网站。我已经尝试过使用 postUrl()
,它似乎工作...但仅限于一些网站。
I have an android application that consists of a WebWiew
and I need to login to a site automatically using code. I've tried using postUrl()
and it seems to work... but only on some sites.
这里的code我使用:
Here's the code I'm using:
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"));
}
}
该作品的伟大作为dropbox.com,但其他网站,如google.com,facebook.com等只是加载登录页面或给出错误(google.com给出了一个错误,说我需要启用cookies)。
This Works great for dropbox.com, but other sites like google.com, facebook.com, etc. just load the login page or give an error (google.com gives an error saying I need to enable cookies).
现在我只是要用手后的数据;看着站点的登录表单,并投入了POSTDATA名称/值字段在我的code。在网站,如谷歌,登录表单有许多隐藏的领域,我已经将那些到POSTDATA也。
Right now I'm just going the post data by hand; looking at the login form for the site and putting the name/value fields in the postData in my code. On sites like google, the login form has many hidden fields and I've been adding those to the postData also.
如果任何人都可以给我什么我做错了,请让我知道什么想法,我是pretty的困惑这一点。
If anyone could give me any idea of something I'm doing wrong please let me know, I'm pretty confused about this.
推荐答案
尝试更换UTF-8
(在第2个参数)与 BASE64
。
Try replacing "utf-8"
(in the 2nd param) with "BASE64"
.
这篇关于如何发送与code POST数据在Android的WebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!