ฉันกำลังพยายามส่งคำขอโพสต์ด้วยการวอลเลย์ไม่สำเร็จ
lib ทำงานอย่างถูกต้อง และฉันจัดการเพื่อส่งคำขอสตริงบางส่วนได้ แต่การโพสต์ด้วย JsonObject ไม่ทำงาน
String urlJsonReq = "https://api.parse.com/1/classes/GameScore";
String tag_json_obj = "tag_json";
JsonObjectRequest jsonReq = new JsonObjectRequest(Request.Method.POST,
urlJsonReq,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d("MyApp", response.toString());
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d("MyApp", "Error: " + error.getMessage());
// hide the progress dialog
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("value1", "testValue1");
params.put("value2", "testValue2");
return params;
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("X-Parse-REST-API-Key", "xxxxxxxxxxxx");
headers.put("X-Parse-Application-Id", "xxxxxxxxxxx");
return headers;
}
@Override
public String getBodyContentType() {
return "application/json";
}
};
ฉันยังคงได้รับข้อผิดพลาด ฉันอ่านเจอที่ไหนสักแห่ง แต่ไม่มีรายละเอียดใด ๆ ที่ วอลเลย์ ไม่สามารถส่ง JsonObjects ได้ แต่จะได้รับเท่านั้น หากคุณต้องการแก้ไขปัญหานั้นคุณควรใช้คลาสที่กำหนดเอง แต่ฉันไม่รู้จริงๆว่าฉันแค่ทำผิดพลาดโง่ ๆ ที่นี่หรือไม่ (เป็นไปได้)
พวกคุณรู้อะไรเกี่ยวกับเรื่องนั้นบ้างไหม?
ขอขอบคุณสำหรับเวลาของคุณ.