android webview post 劫持,在Android中对WebView的HTTP POST响应

我正在尝试使用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 nameValuePairs = new ArrayList();

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 + "

errorCode: "

+ errorCode + "

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 setFormData

02-21 11:42:38.539: E/webviewdatabase(2848): java.net.MalformedURLException: Unknown protocol: about

02-21 11:42:38.539: E/webviewdatabase(2848): at java.net.URL.(URL.java:288)

02-21 11:42:38.539: E/webviewdatabase(2848): at java.net.URL.(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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值