Trước hết, hãy để tôi nói rằng tôi không thể tin rằng webview lại hút quá nhiều.
Đây là những gì tôi đã làm để vượt qua tiêu đề tùy chỉnh
public class CustomWebview extends WebView {
public void loadWithHeaders(String url) {
setWebViewClient(new WebViewClient() {
@Override
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
* @param 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;
}
}
}
1 @stotherd bạn đã nhận được bất kỳ giải pháp cho vấn đề này tôi đang mắc kẹt với điều này quá và không thể tìm thấy giải pháp? –
Không may là không, tôi phải yêu cầu riêng từng tài nguyên, và sau đó không hoàn thành dự án. – stotherd