80,348
社区成员
发帖
与我相关
我的任务
分享
JSONObject params = new JSONObject();
try {
params.put("username", phone);
params.put("password", password);
params.put("type", "1");
} catch (JSONException e) {
e.printStackTrace();
}
getHttpData(Url.URL_LOGIN, params);
public void getHttpData(final String url,JSONObject param) {
JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, url,param, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject jsonObject) {
handleData(jsonObject);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
handleError(volleyError);
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<>();
headers.put("Accept", "application/json");
headers.put("Content-Type", "application/json; charset=UTF-8");
return headers;
}
};
//超时时间10s,最大重连次数2次
request.setRetryPolicy(new DefaultRetryPolicy(10 * 1000, 2, 1.0f));
HttpManager.addRequest(request);
}