我想查看从网页到Android设备whether it is POST request or GET request as in Google Chrome browser
的请求。请告诉我怎么做。
注意:我想在WebView's Override method
的任何一个中进行如下检查。
if request.method == 'GET':
do_something()
elif request.method == 'POST':
do_something_else()
编辑1:我曾尝试登录Google。我得到了“POST”如下。我试过用Android WebView使用方法onFormResubmission。但没有打电话。
@Override
public void onFormResubmission(WebView view, Message dontResend, Message resend) {
super.onFormResubmission(view, dontResend, resend);
}
答案 0 :(得分:0)
使用自定义WebViewClient如下所示
WebView webview = new WebView(this){
@Override
public void loadData(String data, String mimeType, String encoding) {
Log.d("TAGloadData", data+" ==> "+mimeType+" "+encoding);
super.loadData(data, mimeType, encoding);
}
@Override
public void loadUrl(String url, Map<String, String> extraHeaders) {
Log.d("TAGloadUrl", " ==> "+extraHeaders);
super.loadUrl(url, extraHeaders);
}
@Override
public void loadDataWithBaseURL(String baseUrl, String data,
String mimeType, String encoding, String historyUrl) {
Log.d("TAGloadUrlB", " ==> "+data);
super.loadDataWithBaseURL(baseUrl, data, mimeType, encoding, historyUrl);
}
@Override
public void loadUrl(String url) {
if(!url.startsWith("method"))
Log.d("TAGForm", " ==> using Post method");
else{
url = url.replaceFirst("method","");
Log.d("TAGForm", " ==> using Get method"+url);
}
super.loadUrl(url);
Log.d("TAGloadUrl", " ==> "+url);
}
};
答案 1 :(得分:0)
HttpURLConnection con = (HttpURLConnection) url.openConnection();
String reqMethod = con.getRequestMethod();
通过这种方式,您可以获得确切的方法