gpt4 book ai didi

java - 无法使用 JSONObjectRequest 将数据发布到服务器

转载 作者:行者123 更新时间:2023-12-02 12:04:52 25 4
gpt4 key购买 nike

这是我将数据发布到服务器的方法,但无法发布。我必须将数据发布到服务器,我正在使用 JsonObjectRequest 是否有其他方法来发布数据,请帮助我。

 private void postNoticeData() {
final String noticeTitle = postTitle.getText().toString();
final String description = postDescription.getText().toString();

Map<String, String> params = new HashMap<String, String>();
params.put(KEY_NOTICE_TITLE, noticeTitle);
params.put(KEY_NOTICE_DESCRIPTION, description);



JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST,
URL_DATA,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.i("@school", "Response - " + response);
Toast.makeText(AddNoticeAdmin.this.getApplication(), "Added Successfully", Toast.LENGTH_SHORT).show();
AddNoticeAdmin.this.NavigateToNotice();
progressDialog.dismiss();

}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.i("@school", "Error - " + error.getMessage());
Toast.makeText(AddNoticeAdmin.this.getApplication(), "Check your Internet Connection", Toast.LENGTH_SHORT).show();
progressDialog.dismiss();
}
});
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(jsonObjectRequest);
}

它显示截击错误,请帮助我

最佳答案

将Post方法写在URL后面,如下:

 JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST,
URL_DATA, postNotice(),
new Response.Listener<JSONObject>() {

}

postNotice 方法

private String postNotice() {
// Your POJO Class();
// the Data to be Posted using the PojoClass Object;

return new Gson().toJson(pojoClassObject);
}

希望有帮助

关于java - 无法使用 JSONObjectRequest 将数据发布到服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46967871/

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