all
I want to POST url in webview with custom user-agent,how can i do it?
I know
webView.loadUrl(url,extraHeaders);
can with the custom head data,but the request is GET
and,
webView.postUrl(v, EncodingUtils.getBytes(data, "base64"));
can POST the data,but it can't change the head data...
How can I do it ?
Before using postUrl have your tried something along the lines of:
WebSettings settings = mWebView.getSettings();
settings.setUserAgentString("<Add User Agent Here>");
mWebView.postUrl(.....);
Related
I can not load web pages using webview,Nothing is displayed,
this url "http://dev.51yunche.com:7000/WeChat/Service%20introduce.html",
this is my webview
webView = (WebView) findViewById(R.id.drive_web);
webView.setWebViewClient(new WebViewClient());
webview.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setAppCacheEnabled(true);
webView.getSettings().setDomStorageEnabled(true);//DOM Storage
webView.loadUrl("http://dev.51yunche.com:7000/WeChat/Service%20introduce.html");
this xml:
<WebView
android:id="#+id/drive_web"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
The console does not have any prompts or error messages。I'd like to hear some input from more experienced WebView users (and developers?).
Thank you in advance!
This is not webview Issue.In web browser also that url display Nothing.check that Backend or design code of your html file.
You have a space encoded character %20 in your URL...
use a valid url like:
webView.loadUrl("http://dev.51yunche.com:7000/WeChat/Serviceintroduce.html");
Alternatively you can also try URLEncoder.encode(YOUR_URL); function to encode the Url
Your link itself doesn't display anything in web browser. If you still have any doubt, just simply create a normal html page by yourself and run it from your local system and check it out.
I use webview to load local html data like this
webview.loadDataWithBaseURL("about:blank", finalSrc, "text/html", "UTF-8", null);
the finalSrc is a variable of html string.
sometimes, the webview can display the corrent content,but sometimes not.
and I found that if I clear the cache of my app, the webview works well again.
so what's wrong with my app?
rather than using BaseUrl why don't use loadData. for example
webview.loadData(finalSrc, "text/html", "UTF-8");
I need to make x-www-form-urlencoded post request from Android webView client. I am using EncodingUtils for encoding. Here is my code:
String postdata = "sUrl=http%3A%2F%2Flocalhost%3A9000%2Fpayment%2Fpayu%2Fresponse&......."
.......
.......
webView.postUrl("https://test.payu.in/_payment", EncodingUtils.getBytes(POSTDATA, "BASE64"));
I am using BASE64 but what supposed to be there for x-www-form-urlencided? I tried to search but nothing is there. What is the right approach to do it?
Its simple, use a html form and put it inside viewview
webView.loadDataWithBaseURL("file:///android_asset/index.html", , "text/html", "UTF-8", null);
I am performing a POST to the Android webview where the expected response is a PDF file. However the webview just shows a blank page. I realise that PDF files cannot be rendered in the webview but would expect the file to start downloading or show some response at least.
Does anyone know if its possible to POST to a webview to initiate download of a (pdf) file?
_webView = FindViewById<WebView>(Resource.Id.ebookWebview);
_webView.SetWebViewClient(webviewClient);
_webView.SetWebChromeClient(new WebChromeClient());
_webView.Settings.AllowFileAccess = true;
_webView.Settings.JavaScriptEnabled = true;
_webView.PostUrl(_postUrl, EncodingUtils.GetBytes(_postData, "BASE64"));
Have you tried registering a DownloadListener on the WebView? That is needed to handle the download. Please see http://developer.android.com/reference/android/webkit/WebView.html#setDownloadListener(android.webkit.DownloadListener)
I'm getting a 404 in a webview using the following code . . .
LocateBrowser = (WebView)findViewById(R.id.locatebrowser);
LocateBrowser.setWebViewClient(new WebViewClient());
LocateBrowser.loadUrl("http://maps.google.com/maps?z=17&t=h&q=loc:31.8526,-110.9959");
If I copy that url into a browser on my PC, it works just fine.
If I don't implement the WebViewClient (the second line), the browser on the Android device opens up and displays the map properly. But I don't want it to do that, I want it to show in my WebView. The map looks like this in the external browser...
The problem is the above code first displays the screen above without the map and an indeterminate progress "Loading . . ." symbol for about a second and then displays google's 404 page saying "the URL /Search was not found on this server".
Is there something else I need to do?
Thanks,
Gary
What is wrong to use the WebViewClient ? If it works with that solution without using a the map api, that would be ok.
What is you aim ?
I failed to enable java script. Following code works but it produces a screen real estate problem.
LocateBrowser = (WebView)findViewById(R.id.locatebrowser);
LocateBrowser.setWebViewClient(new WebViewClient());
WebSettings webSettings = LocateBrowser.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setLoadWithOverviewMode(true);
LocateBrowser.loadUrl("http://maps.google.com/maps?z=17&t=h&q=loc:31.8526,-110.9959");