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 :
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> map = new HashMap<>();
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:-
- Implement a
webview
in your app without any UI (if you are expecting Json response). - Override
onPageFinished
insidesetWebwiewclient()
. - get the page cookie by :
String cookies = CookieManager.getInstance().getCookie(url);
- after getting cookie pass the cookie in header of volley request
by
key="cookie"
code reference:-
WebView webViewRequest=new WebView("your app context");
webViewRequest.getSettings().setJavaScriptEnabled(true);
webViewRequest.setWebViewClient(new WebViewClient());
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(new WebViewClient(){
@Override
public void onPageFinished(WebView view, String url) {
cookies = CookieManager.getInstance().getCookie(url);//here you will get cookie
Log.d(TAG, "onPageFinished: "+cookies);
StringRequest Request = new StringRequest(url, new
Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d(TAG, "onResponse: "+response.toString());
// your data from server
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}){
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> map = new HashMap<>();
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"