
我正在尝试使用http连接到该页面
帖子.我做一个用于创建的http帖子
一个webvIEw.我需要从webvIEw重定向到另一个页面.但是当单击“继续”按钮时会抛出异常.
我的代码是
public class ZhttpPostProjActivity extends Activity { /** Called when the activity is first created. */ private WebVIEw mWebVIEw; private ProgressDialog progressbar; private static final String TAG = "ZhttpPostProjActivity"; @OverrIDe public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.web_vIEw); mWebVIEw = (WebVIEw) findVIEwByID(R.ID.webvIEw); WebSettings webSettings = mWebVIEw.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setDomStorageEnabled(true); progressbar = ProgressDialog.show(ZhttpPostProjActivity.this, "", "Loading..."); postData(); } private final String URL_REGISTER = "https://www.paypal.com/checkout"; public voID postData() { BufferedReader bufferedReader = null; try { List<nameValuePair> nameValuePairs = new ArrayList<nameValuePair>(); nameValuePairs.add(new BasicnameValuePair("username", "username")); nameValuePairs.add(new BasicnameValuePair("password", "password")); httpClIEnt httpclIEnt = new DefaulthttpClIEnt(); httpPost httppost = new httpPost(URL_REGISTER); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, http.UTF_8)); httpResponse response = httpclIEnt.execute(httppost); bufferedReader = new BufferedReader(new inputStreamReader(response .getEntity().getContent())); StringBuffer stringBuffer = new StringBuffer(""); String line = ""; String lineseparator = System.getProperty("line.separator"); while ((line = bufferedReader.readline()) != null) { stringBuffer.append(line + lineseparator); } bufferedReader.close(); String webData = stringBuffer.toString(); Log.i(TAG + "web data : ", webData); // String webData = new // BasicResponseHandler().handleResponse(response); Log.i(TAG, "httppost.getURI().toString(): " + httppost.getURI().toString()); mWebVIEw.setWebVIEwClIEnt(new WebVIEwClIEnt() { public boolean shouldOverrIDeUrlLoading(WebVIEw vIEw, String url) { Log.i(TAG, "Processing webvIEw url click..."); vIEw.loadUrl(url); return true; } public voID onPageFinished(WebVIEw vIEw, String url) { Log.i(TAG, "Finished loading URL: " + url); if (progressbar.isShowing()) { progressbar.dismiss(); } } public voID onReceivedError(WebVIEw vIEw, int errorCode, String description, String failingUrl) { Log.e(TAG, "Error: " + description + " \n errorCode: " + errorCode + "\n failingUrl: " + failingUrl); } }); // mWebVIEw.loadUrl(httppost.getURI().toString()); mWebVIEw.loadData(webData, "text/HTML", "UTF-8"); mWebVIEw.loadDataWithBaseURL(httppost.getURI().toString(), webData, "text/HTML", http.UTF_8, null); } catch (Exception ex) { ex.printstacktrace(); } }在WebvIEw中单击“继续”按钮时会抛出异常
02-21 11:42:38.539: E/webvIEwdatabase(2848): Failed in setFormData02-21 11:42:38.539: E/webvIEwdatabase(2848): java.net.MalformedURLException: UnkNown protocol: about02-21 11:42:38.539: E/webvIEwdatabase(2848): at java.net.URL.<init>(URL.java:288)02-21 11:42:38.539: E/webvIEwdatabase(2848): at java.net.URL.<init>(URL.java:157)02-21 11:42:38.539: E/webvIEwdatabase(2848): at androID.webkit.WebVIEwDatabase.setFormData(WebVIEwDatabase.java:1032)02-21 11:42:38.539: E/webvIEwdatabase(2848): at androID.webkit.browserFrame.loadStarted(browserFrame.java:384)02-21 11:42:38.539: E/webvIEwdatabase(2848): at androID.webkit.JWebCoreJavaBrIDge.sharedTimerFired(Native Method)02-21 11:42:38.539: E/webvIEwdatabase(2848): at androID.webkit.JWebCoreJavaBrIDge.fireSharedTimer(JWebCoreJavaBrIDge.java:91)02-21 11:42:38.539: E/webvIEwdatabase(2848): at androID.webkit.JWebCoreJavaBrIDge.handleMessage(JWebCoreJavaBrIDge.java:108)02-21 11:42:38.539: E/webvIEwdatabase(2848): at androID.os.Handler.dispatchMessage(Handler.java:99)02-21 11:42:38.539: E/webvIEwdatabase(2848): at androID.os.Looper.loop(Looper.java:123)02-21 11:42:38.539: E/webvIEwdatabase(2848): at androID.webkit.WebVIEwCore$WebCoreThread.run(WebVIEwCore.java:673)02-21 11:42:38.539: E/webvIEwdatabase(2848): at java.lang.Thread.run(Thread.java:1019)02-21 11:42:41.324: E/cache(2848): illegal expires: Sat, Jan 01 2000 01:01:01 GMT解决方法:
像这样使用
WebVIEw webvIEw = new WebVIEw(this);setContentVIEw(webvIEw);byte[] post = EnCodingUtils.getBytes("postvariable=value&nextvar=value2", "BASE64");webvIEw.postUrl("http://www.geenIE.nl/AnHeli/mobile/ranking/demo/index.PHP", post); 总结 以上是内存溢出为你收集整理的在Android中对WebView的HTTP POST响应全部内容,希望文章能够帮你解决在Android中对WebView的HTTP POST响应所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)