我想使用 webview 发出一个 http post 请求。
webView.setWebViewClient(new WebViewClient(){
public void onPageStarted(WebView view, String url,
Bitmap favicon) {
super.onPageStarted(view, url, favicon);
}
public boolean shouldOverrideUrlLoading(WebView view,
String url) {
webView.postUrl(Base_Url, postData.getBytes());
return true;
}
});
上面的代码 fragment 加载了网页。我想访问此请求的响应。
如何使用 webview 获取 http post 请求的响应?
提前致谢
最佳答案
首先在你的gradle文件中加入http库的支持: 为了能够使用
useLibrary 'org.apache.http.legacy'
在此之后,您可以使用以下代码在您的 webview 中执行发布请求:
public void postUrl (String url, byte[] postData)
String postData = "submit=1&id=236";
webview.postUrl("http://www.belencruzz.com/exampleURL",EncodingUtils.getBytes(postData, "BASE64"));
http://belencruz.com/2012/12/do-post-request-on-a-webview-in-android/
关于android - 如何使用 webview 发出 post 请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13452289/