JSONObject jsonAddress = new JSONObject();
try {
jsonAddress.put("Country", "Country");
jsonAddress.put("Region", "Region");
jsonAddress.put("City", "Region");
jsonAddress.put("Street", "Street");
jsonAddress.put("Number", "10");
jsonAddress.put("Building", "A");
jsonAddress.put("Floor", "2");
jsonAddress.put("Apartment", "8");
} catch (JSONException e) {
e.printStackTrace();
}
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("email", email);
jsonObject.put("hashedPassword", hashedPassword);
jsonObject.put("institutionName", institutionName);
jsonObject.put("institutionAddress", jsonAddress);
} catch (JSONException e) {
e.printStackTrace();
}
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST,
sv_url, jsonObject,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
System.out.println(response.toString());
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
});
RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext());
requestQueue.add(jsonObjReq);
你好,我试图使用JsonObjectRequest做一个POST请求,向服务器发送3个字符串和1个JSONOjbect,以便创建一个 "机构",但无论我做什么都得到同样的错误。我尝试了很多 "解决方案",但都没有成功。
E/Volley: [1167] BasicNetwork.performRequest: Unexpected response code 500 for http://fiscaldocumentseditest.azurewebsites.net/Institution/Create.php
W/System.err: com.android.volley.ServerError
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:205)
at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:131)
at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:111)
at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:90)
为什么你不google?on SO很多相同的问题。