使用此站点必须先启用java,Volley Server错误,此站点需要启用Java脚本

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 issue I found these two questions..

Volley Server error (Requires javascript?) Android Development but there is no answer to solve this issue in 2 months

No more questions and solution found. Can anyone tell the exact problem and solution with this issue.

Here is my code

public void postRequest(final JSONObject jsonParams,final Handler handler){

StringRequest stringRequest = new StringRequest(Request.Method.POST, AppConstants.ADMIN_URL,

new Response.Listener() {

@Override

public void onResponse(String response) {

Message message = handler.obtainMessage();

message.obj = response;

handler.sendMessage(message);

}

},

new Response.ErrorListener() {

@Override

public void onErrorResponse(VolleyError error) {

Message message = handler.obtainMessage();

message.obj = error.toString();

Log.d("error",error.toString());

handler.sendMessage(message);

}

}){

@Override

protected Map getParams(){

Map params = new HashMap();

Iterator iter = jsonParams.keys();

while (iter.hasNext()) {

try {

String key = iter.next();

String value = jsonParams.get(key)+"";

params.put(key,value);

} catch (JSONException e) {

// Something went wrong!

Message message = handler.obtainMessage();

message.obj = e.getMessage();

handler.sendMessage(message);

}

}

return params;

}

@Override

public Map getHeaders() throws AuthFailureError {

Map headers = new HashMap();

return headers;

}

};

MyVolley.getInstance(context).getRequestQueue().add(stringRequest);

}

and web service code is

解决方案

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 getHeaders() throws AuthFailureError {

Map map = new HashMap<>();

map.put("Cookie", "__test=YOUR COOKIE HERE; expires=Friday, January 1, 2038 at 5:25:55 AM; path=/");

return map;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值