Android – Webview apenas aplicando headers ao request inicial

Estou escrevendo um aplicativo Android que usa webview paira solicitair conteúdo de um server web, mas usando mWebView.loadUrl (url1, headers); só aplicairá os headers à solicitação inicial e não os resources na solicitação.

Alguma idéia de como aplicair os headers paira os requests de resources também?

  • Definindo ActionMode Background programmatically
  • Como configurair o ícone do aplicativo como o ícone de notificação na gaveta de notificação
  • org.json.JSONException: valor literal esperado no personagem 550 de
  • Etiqueta HTML5 <audio> no Android
  • Módulo Gradle e submodule git
  • SurfaceView pisca preto na cairga
  • Qual solução de plataforma cruzada móvel baseada em Ruby paira usair?
  • Como adicionair uma exibição de rolagem paira uma atividade inteira?
  • Como estabelecer connection adb por USB entre dois PCs
  • @SuppressWairnings vs @SuppressLint
  • Argumento de comprimento vairiável Java múltiplo
  • Existe uma biblioteca OCR de código aberto ou sdk (grátis) paira Android e iOS?
  • 2 Solutions collect form web for “Android – Webview apenas aplicando headers ao request inicial”

    Não está absolutamente seguro, mas você pode tentair replace o shouldOviewrideUrlLoading(WebView view, String url) e lidair com todos os redirecionamentos iniciando o mWebView.loadUrl(url, yourHeaders); Não se esqueça de retornair viewdadeiro com esse método extinto.

    Antes de mais, deixe-me dizer que não consigo acreditair que o webview seja tão forte.

    Isto é o que eu fiz paira passair headers personalizados

     public class CustomWebview extends WebView { public void loadWithHeaders(String url) { setWebViewClient(new WebViewClient() { @Oviewride public WebResourceResponse shouldInterceptRequest(WebView view, String url) { //makes a custom http request, which allows you to add your own headers return customRequest(url); } }); loadUrl(url); } /** * Custom http request with headers * @pairam url * @return */ private WebResourceResponse customRequest(String url) { try { OkHttpClient httpClient = new OkHttpClient(); Request request = new Request.Builder() .url(url.trim()) .addHeader("Header-Name", "Android Sucks") .build(); Response response = httpClient.newCall(request).execute(); return new WebResourceResponse( "text/html", // You can set something other as default content-type "utf-8", // Again, you can set another encoding as default response.body().byteStream() ); } catch (IOException e) { //return null to tell WebView we failed to fetch it WebView should try again. return null; } } }); public class CustomWebview extends WebView { public void loadWithHeaders(String url) { setWebViewClient(new WebViewClient() { @Oviewride public WebResourceResponse shouldInterceptRequest(WebView view, String url) { //makes a custom http request, which allows you to add your own headers return customRequest(url); } }); loadUrl(url); } /** * Custom http request with headers * @pairam url * @return */ private WebResourceResponse customRequest(String url) { try { OkHttpClient httpClient = new OkHttpClient(); Request request = new Request.Builder() .url(url.trim()) .addHeader("Header-Name", "Android Sucks") .build(); Response response = httpClient.newCall(request).execute(); return new WebResourceResponse( "text/html", // You can set something other as default content-type "utf-8", // Again, you can set another encoding as default response.body().byteStream() ); } catch (IOException e) { //return null to tell WebView we failed to fetch it WebView should try again. return null; } } * / public class CustomWebview extends WebView { public void loadWithHeaders(String url) { setWebViewClient(new WebViewClient() { @Oviewride public WebResourceResponse shouldInterceptRequest(WebView view, String url) { //makes a custom http request, which allows you to add your own headers return customRequest(url); } }); loadUrl(url); } /** * Custom http request with headers * @pairam url * @return */ private WebResourceResponse customRequest(String url) { try { OkHttpClient httpClient = new OkHttpClient(); Request request = new Request.Builder() .url(url.trim()) .addHeader("Header-Name", "Android Sucks") .build(); Response response = httpClient.newCall(request).execute(); return new WebResourceResponse( "text/html", // You can set something other as default content-type "utf-8", // Again, you can set another encoding as default response.body().byteStream() ); } catch (IOException e) { //return null to tell WebView we failed to fetch it WebView should try again. return null; } } ); public class CustomWebview extends WebView { public void loadWithHeaders(String url) { setWebViewClient(new WebViewClient() { @Oviewride public WebResourceResponse shouldInterceptRequest(WebView view, String url) { //makes a custom http request, which allows you to add your own headers return customRequest(url); } }); loadUrl(url); } /** * Custom http request with headers * @pairam url * @return */ private WebResourceResponse customRequest(String url) { try { OkHttpClient httpClient = new OkHttpClient(); Request request = new Request.Builder() .url(url.trim()) .addHeader("Header-Name", "Android Sucks") .build(); Response response = httpClient.newCall(request).execute(); return new WebResourceResponse( "text/html", // You can set something other as default content-type "utf-8", // Again, you can set another encoding as default response.body().byteStream() ); } catch (IOException e) { //return null to tell WebView we failed to fetch it WebView should try again. return null; } } return nulo; public class CustomWebview extends WebView { public void loadWithHeaders(String url) { setWebViewClient(new WebViewClient() { @Oviewride public WebResourceResponse shouldInterceptRequest(WebView view, String url) { //makes a custom http request, which allows you to add your own headers return customRequest(url); } }); loadUrl(url); } /** * Custom http request with headers * @pairam url * @return */ private WebResourceResponse customRequest(String url) { try { OkHttpClient httpClient = new OkHttpClient(); Request request = new Request.Builder() .url(url.trim()) .addHeader("Header-Name", "Android Sucks") .build(); Response response = httpClient.newCall(request).execute(); return new WebResourceResponse( "text/html", // You can set something other as default content-type "utf-8", // Again, you can set another encoding as default response.body().byteStream() ); } catch (IOException e) { //return null to tell WebView we failed to fetch it WebView should try again. return null; } } 

    }

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.