gpt4 book ai didi

Android Volley 意外响应代码 400

转载 作者:可可西里 更新时间:2023-11-01 17:02:12 27 4
gpt4 key购买 nike

我正在使用 Volley 作为登录功能,但我收到了 https 的意外响应代码 400。

它可以在 WiFi 上工作,但不能在蜂窝网络上工作,并且该问题只发生在选定的手机型号上。下面是我的代码。

public void LoginRequest(final String username,final String password,final ActionResponse success,final Action err ){
RequestQueue queue = MVolleyRequests.getInstance(mContext).getRequestQueue();

StringRequest sr = new StringRequest(com.android.volley.Request.Method.POST,LOGIN_URL,
new Listener<String>() {
@Override
public void onResponse(String response) {
success.action(MError.getError(Integer.parseInt(response)));
}
}, new ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
err.action();
}
}){

@Override
protected Map<String,String> getParams(){
Map<String,String> params = new HashMap<String, String>();
params.put("id", username);
params.put("pwd", password);
params.put("version", "2.5" );
return params;
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String,String> params = new HashMap<String, String>();
params.put("Content-Type","application/x-www-form-urlencoded; charset=utf-8");
return params;
}
};
sr.setRetryPolicy(new DefaultRetryPolicy(
60000,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
MVolleyRequests.getInstance(mContext).addToRequestQueue(sr);

}

最佳答案

试试这个:

JSONObject params = new JSONObject();

try {
params.put("id", username);
params.put("pwd", password);
params.put("version", "2.5" );
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//

JsonObjectRequest jsonObjReq = new JsonObjectRequest(Method.POST,
url, params,
new Response.Listener<JSONObject>() {

@Override
public void onResponse(JSONObject response) {
Log.d(TAG, response.toString());
}
}, new Response.ErrorListener() {

@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
}
}) {

/**
* Passing some request headers
* */
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json; charset=utf-8");
return headers;
}

};
jsonObjReq.setRetryPolicy(new DefaultRetryPolicy(60000,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

// Adding request to request queue
getRequestQueue(jsonObjReq);

关于Android Volley 意外响应代码 400,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26237600/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com