Skip to content Skip to sidebar Skip to footer

Volley Server Error This Site Requires Java Script Enabled

I am using volley to send web service request and volley response is SERVER ERROR (this site requires java script enabled). I tried POST and GET methods. After some search on this

Solution 1:

There is a nice workaround suggested in this answer.

In Volley, you can override getHeaders() method to send the cookie with your HTTP request.

Code :

@OverridepublicMap<String, String> getHeaders() throws AuthFailureError {
    Map<String, String> map = newHashMap<>();
    map.put("Cookie", "__test=YOUR COOKIE HERE; expires=Friday, January 1, 2038 at 5:25:55 AM; path=/");
    return map;
}

Solution 2:

i faced the same problem , and there is no direct solution for this problem is:- some servers won't allow these type requests , they allow only web browsers

solution:-

  1. Implement a webview in your app without any UI (if you are expecting Json response).
  2. Override onPageFinished inside setWebwiewclient().
  3. get the page cookie by : String cookies = CookieManager.getInstance().getCookie(url);
  4. after getting cookie pass the cookie in header of volley request by key="cookie"

code reference:-

WebView webViewRequest=newWebView("your app context");

    webViewRequest.getSettings().setJavaScriptEnabled(true);
    webViewRequest.setWebViewClient(newWebViewClient());
    webViewRequest.getSettings().setLoadWithOverviewMode(true);
    webViewRequest.getSettings().setUseWideViewPort(true);
    webViewRequest.getSettings().setSupportZoom(false);
    webViewRequest.getSettings().setBuiltInZoomControls(false);
    webViewRequest.getSettings().setDisplayZoomControls(false);
    webViewRequest.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    webViewRequest.requestFocusFromTouch();
    webViewRequest.getSettings().setAppCacheEnabled(false);
    webViewRequest.setScrollbarFadingEnabled(false);

    webViewRequest.setWebViewClient(newWebViewClient(){


        @OverridepublicvoidonPageFinished(WebView view, String url) {
      cookies = CookieManager.getInstance().getCookie(url);//here you will get cookieLog.d(TAG, "onPageFinished: "+cookies);
            StringRequestRequest = newStringRequest(url, newResponse.Listener<String>() {


                @OverridepublicvoidonResponse(String response) {
                    Log.d(TAG, "onResponse: "+response.toString());
                   // your data from server
                }
            }, newResponse.ErrorListener() {
                @OverridepublicvoidonErrorResponse(VolleyError error) {

                }
            }){
                @OverridepublicMap<String, String> getHeaders() throws AuthFailureError {

                    Map<String, String> map = newHashMap<>();
                    map.put("Cookie", cookies);
                    return map;
                }
            };
            Mysingleton.getMinstance(DashboardActivity.context).addToRequestQue(Request);

        }
    });
    webViewRequest.loadUrl("your url here");

}

Solution 3:

I came across this error recently! Your code is totally fine but the problem lies with your web host. (Is it byethost)? It has a bot detector running which does not let your Android volley request in.Unfortunately this cannot be disabled /turned off. Try changing your web hosting service. Hope this helps☺

Post a Comment for "Volley Server Error This Site Requires Java Script Enabled"