嗨我想發送刪除請求服務器使用齊射和身體參數齊射。但我無法發送請求成功刪除請求使用標題和參數排序
我曾嘗試
JSONObject jsonbObjj = new JSONObject();
try {
jsonbObjj.put("nombre", Integer.parseInt(no_of_addition
.getText().toString()));
jsonbObjj.put("cru", crue);
jsonbObjj.put("annee", 2010);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
VolleyRequest mVolleyRequest = new VolleyRequest(
Method.DELETE, url, jsonbObjj,
new Listener<JSONObject>() {
@Override
public void onResponse(JSONObject jsonObject) {
// TODO Auto-generated method stub
if (pDialog != null) {
pDialog.dismiss();
}
Log.e("Server Response", "response = "
+ jsonObject.toString());
}
}, new ErrorListener() {
@Override
public void onErrorResponse(VolleyError arg0) {
// TODO Auto-generated method stub
if (pDialog != null) {
pDialog.dismiss();
}
Log.e("Error Response",
"Error " + arg0.getMessage());
Log.e("Error Response",
"Error = " + arg0.getCause());
}
}, mUserSession.getUserEmail(), mUserSession
.getUserPassword(), false);
ApplicationController.getInstance().addToRequestQueue(
mVolleyRequest, "deleteRequest");
,這裏是我的VolleyRequest請求類
public class VolleyRequest extends JsonObjectRequest {
String email, pass;
boolean saveCookeis;
public VolleyRequest(int method, String url, JSONObject jsonRequest,
Listener<JSONObject> listener, ErrorListener errorListener,
String email, String pass, boolean saveCookie) {
super(method, url, jsonRequest, listener, errorListener);
// TODO Auto-generated constructor stub
this.email = email;
this.pass = pass;
this.saveCookeis = saveCookie;
}
public VolleyRequest(int method, String url, JSONObject jsonRequest,
Listener<JSONObject> listener, ErrorListener errorListener) {
super(Method.POST, url, jsonRequest, listener, errorListener);
// TODO Auto-generated constructor stub
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
// TODO Auto-generated method stub
HashMap<String, String> params = new HashMap<String, String>();
String auth = "";
try {
auth = android.util.Base64.encodeToString(
(this.email + ":" + this.pass).getBytes("UTF-8"),
android.util.Base64.DEFAULT);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
params.put("Authorization", auth);
return params;
}
@Override
protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) {
// TODO Auto-generated method stub
if (saveCookeis) {
try {
String jsonString = new String(response.data,
HttpHeaderParser.parseCharset(response.headers));
ApplicationController.getInstance().checkSessionCookie(
response.headers);
return Response.success(new JSONObject(jsonString),
HttpHeaderParser.parseCacheHeaders(response));
} catch (UnsupportedEncodingException e) {
return Response.error(new ParseError(e));
} catch (JSONException je) {
return Response.error(new ParseError(je));
}
}
return super.parseNetworkResponse(response);
}
}
當我嘗試這種代碼,我得到400響應代碼錯誤請讓我知道,如果任何人都可以幫助我..那我做錯了什麼。謝謝
這裏的屏幕截圖刪除Api我測試和它的工作正常。
嗨!由於我沒有工作憑證(用戶,傳遞),所以我的服務器URL的響應代碼是500,而不是400 :) – BNK
我認爲你可以嘗試'params.put(「Authorization」,「Basic」+ auth);' – BNK
它不能使用params。並且m從應用程序發送請求時得到400,但是當我從瀏覽器打到URL時,它運行良好..我的用戶名在圖像中指定,傳遞爲1234,如果您可以檢查,請檢查並告訴我做錯了什麼。謝謝 –