send data with JSON and volley
I'm trying to send data using volley and JSON to web service but I don't know how to put the data into my string request correctly

my code
String url = "http://api.jasamedika.co.id/service/pegawai/1200034";
final ProgressDialog loading = ProgressDialog.show(getContext(), "Uploading...", "Please wait...", false, false);
StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.e(TAG, "Response: " + response.toString());
try {
JSONObject jObj = new JSONObject(response);
succes = jObj.getInt(TAG_SUCCESS);
if (succes == 1) {
Toast.makeText(getContext(), jObj.getString(TAG_MESSAGE), Toast.LENGTH_LONG).show();
//kosong();
} else {
Toast.makeText(getContext(), jObj.getString(TAG_MESSAGE), Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
//menghilangkan progress dialog
loading.dismiss();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
//menghilangkan progress dialog
loading.dismiss();
//menampilkan toast
Toast.makeText(getContext(), error.toString(), Toast.LENGTH_LONG).show();
Log.e(TAG, error.getMessage().toString());
}
}) {
@Override
protected Map<String, String> getParams() {
//membuat parameters
Map<String, String> params = new HashMap<String, String>();
//menambah parameter yang di kirim ke web servis
params.put("Content-Type", "application/json");
params.put("ID",id.getText().toString().trim());
params.put("Nama", nama.getText().toString().trim());
params.put("Jenis_Kelamin", jenis_kelamin.getText().toString().trim());
params.put("Tgl_Lahir",tgl_lahir.getText().toString().trim() );
params.put("ID_Jabatan",id_jabatan.getText().toString().trim());
params.put("Salary",salary.getText().toString().trim());
//kembali ke parameters
Log.e(TAG, "" + params);
return params;
}
};
AppController.getInstance().addToRequestQueue(stringRequest, tag_json_obj);
}
error message

java
add a comment |
I'm trying to send data using volley and JSON to web service but I don't know how to put the data into my string request correctly

my code
String url = "http://api.jasamedika.co.id/service/pegawai/1200034";
final ProgressDialog loading = ProgressDialog.show(getContext(), "Uploading...", "Please wait...", false, false);
StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.e(TAG, "Response: " + response.toString());
try {
JSONObject jObj = new JSONObject(response);
succes = jObj.getInt(TAG_SUCCESS);
if (succes == 1) {
Toast.makeText(getContext(), jObj.getString(TAG_MESSAGE), Toast.LENGTH_LONG).show();
//kosong();
} else {
Toast.makeText(getContext(), jObj.getString(TAG_MESSAGE), Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
//menghilangkan progress dialog
loading.dismiss();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
//menghilangkan progress dialog
loading.dismiss();
//menampilkan toast
Toast.makeText(getContext(), error.toString(), Toast.LENGTH_LONG).show();
Log.e(TAG, error.getMessage().toString());
}
}) {
@Override
protected Map<String, String> getParams() {
//membuat parameters
Map<String, String> params = new HashMap<String, String>();
//menambah parameter yang di kirim ke web servis
params.put("Content-Type", "application/json");
params.put("ID",id.getText().toString().trim());
params.put("Nama", nama.getText().toString().trim());
params.put("Jenis_Kelamin", jenis_kelamin.getText().toString().trim());
params.put("Tgl_Lahir",tgl_lahir.getText().toString().trim() );
params.put("ID_Jabatan",id_jabatan.getText().toString().trim());
params.put("Salary",salary.getText().toString().trim());
//kembali ke parameters
Log.e(TAG, "" + params);
return params;
}
};
AppController.getInstance().addToRequestQueue(stringRequest, tag_json_obj);
}
error message

java
2
Use Retrofit, #notAllHeroesWearACape
– Obsthändler
Nov 15 '18 at 9:08
hey check ur response in postman get error .its Data Base Table error
– suresh madaparthi
Nov 15 '18 at 9:14
how to do that ?
– morten jonathan
Nov 15 '18 at 9:16
open postman first
– suresh madaparthi
Nov 15 '18 at 9:18
google.co.in/…
– suresh madaparthi
Nov 15 '18 at 9:19
add a comment |
I'm trying to send data using volley and JSON to web service but I don't know how to put the data into my string request correctly

my code
String url = "http://api.jasamedika.co.id/service/pegawai/1200034";
final ProgressDialog loading = ProgressDialog.show(getContext(), "Uploading...", "Please wait...", false, false);
StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.e(TAG, "Response: " + response.toString());
try {
JSONObject jObj = new JSONObject(response);
succes = jObj.getInt(TAG_SUCCESS);
if (succes == 1) {
Toast.makeText(getContext(), jObj.getString(TAG_MESSAGE), Toast.LENGTH_LONG).show();
//kosong();
} else {
Toast.makeText(getContext(), jObj.getString(TAG_MESSAGE), Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
//menghilangkan progress dialog
loading.dismiss();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
//menghilangkan progress dialog
loading.dismiss();
//menampilkan toast
Toast.makeText(getContext(), error.toString(), Toast.LENGTH_LONG).show();
Log.e(TAG, error.getMessage().toString());
}
}) {
@Override
protected Map<String, String> getParams() {
//membuat parameters
Map<String, String> params = new HashMap<String, String>();
//menambah parameter yang di kirim ke web servis
params.put("Content-Type", "application/json");
params.put("ID",id.getText().toString().trim());
params.put("Nama", nama.getText().toString().trim());
params.put("Jenis_Kelamin", jenis_kelamin.getText().toString().trim());
params.put("Tgl_Lahir",tgl_lahir.getText().toString().trim() );
params.put("ID_Jabatan",id_jabatan.getText().toString().trim());
params.put("Salary",salary.getText().toString().trim());
//kembali ke parameters
Log.e(TAG, "" + params);
return params;
}
};
AppController.getInstance().addToRequestQueue(stringRequest, tag_json_obj);
}
error message

java
I'm trying to send data using volley and JSON to web service but I don't know how to put the data into my string request correctly

my code
String url = "http://api.jasamedika.co.id/service/pegawai/1200034";
final ProgressDialog loading = ProgressDialog.show(getContext(), "Uploading...", "Please wait...", false, false);
StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.e(TAG, "Response: " + response.toString());
try {
JSONObject jObj = new JSONObject(response);
succes = jObj.getInt(TAG_SUCCESS);
if (succes == 1) {
Toast.makeText(getContext(), jObj.getString(TAG_MESSAGE), Toast.LENGTH_LONG).show();
//kosong();
} else {
Toast.makeText(getContext(), jObj.getString(TAG_MESSAGE), Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
//menghilangkan progress dialog
loading.dismiss();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
//menghilangkan progress dialog
loading.dismiss();
//menampilkan toast
Toast.makeText(getContext(), error.toString(), Toast.LENGTH_LONG).show();
Log.e(TAG, error.getMessage().toString());
}
}) {
@Override
protected Map<String, String> getParams() {
//membuat parameters
Map<String, String> params = new HashMap<String, String>();
//menambah parameter yang di kirim ke web servis
params.put("Content-Type", "application/json");
params.put("ID",id.getText().toString().trim());
params.put("Nama", nama.getText().toString().trim());
params.put("Jenis_Kelamin", jenis_kelamin.getText().toString().trim());
params.put("Tgl_Lahir",tgl_lahir.getText().toString().trim() );
params.put("ID_Jabatan",id_jabatan.getText().toString().trim());
params.put("Salary",salary.getText().toString().trim());
//kembali ke parameters
Log.e(TAG, "" + params);
return params;
}
};
AppController.getInstance().addToRequestQueue(stringRequest, tag_json_obj);
}
error message

java
java
edited Nov 15 '18 at 10:48
Milind Mevada
1,550817
1,550817
asked Nov 15 '18 at 8:52
morten jonathanmorten jonathan
306
306
2
Use Retrofit, #notAllHeroesWearACape
– Obsthändler
Nov 15 '18 at 9:08
hey check ur response in postman get error .its Data Base Table error
– suresh madaparthi
Nov 15 '18 at 9:14
how to do that ?
– morten jonathan
Nov 15 '18 at 9:16
open postman first
– suresh madaparthi
Nov 15 '18 at 9:18
google.co.in/…
– suresh madaparthi
Nov 15 '18 at 9:19
add a comment |
2
Use Retrofit, #notAllHeroesWearACape
– Obsthändler
Nov 15 '18 at 9:08
hey check ur response in postman get error .its Data Base Table error
– suresh madaparthi
Nov 15 '18 at 9:14
how to do that ?
– morten jonathan
Nov 15 '18 at 9:16
open postman first
– suresh madaparthi
Nov 15 '18 at 9:18
google.co.in/…
– suresh madaparthi
Nov 15 '18 at 9:19
2
2
Use Retrofit, #notAllHeroesWearACape
– Obsthändler
Nov 15 '18 at 9:08
Use Retrofit, #notAllHeroesWearACape
– Obsthändler
Nov 15 '18 at 9:08
hey check ur response in postman get error .its Data Base Table error
– suresh madaparthi
Nov 15 '18 at 9:14
hey check ur response in postman get error .its Data Base Table error
– suresh madaparthi
Nov 15 '18 at 9:14
how to do that ?
– morten jonathan
Nov 15 '18 at 9:16
how to do that ?
– morten jonathan
Nov 15 '18 at 9:16
open postman first
– suresh madaparthi
Nov 15 '18 at 9:18
open postman first
– suresh madaparthi
Nov 15 '18 at 9:18
google.co.in/…
– suresh madaparthi
Nov 15 '18 at 9:19
google.co.in/…
– suresh madaparthi
Nov 15 '18 at 9:19
add a comment |
3 Answers
3
active
oldest
votes
inside your code
StringRequest stringRequest = new StringRequest(Request.Method.POST,
url,new Response.Listener<String>() {})
change it to
StringRequest stringRequest = new StringRequest(Request.Method.PUT, url,
new Response.Listener<String>() {})
add a comment |
Retrofit are more easy to use
On the first screen you'r method are PUT but in your volley request you use POST,try to change to put
add a comment |
you must send string instead json
you can send by add to hasmap like:
params.put("ID",id.getText().toString().trim());
params.put("user[Nama]", nama.getText().toString().trim());
params.put("user[Jenis_Kelamin]", jenis_kelamin.getText().toString().trim());
params.put("user[Tgl_Lahir]",tgl_lahir.getText().toString().trim() );
params.put("user[ID_Jabatan]",id_jabatan.getText().toString().trim());
params.put("user[Salary]",salary.getText().toString().trim());
enter code here
Did you check screenshot and the parameter body clearly? That (API) request acceptsapplication/jsonnot form url encoded data. You need to send JSON data.
– Shashanth
Nov 15 '18 at 9:24
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53315574%2fsend-data-with-json-and-volley%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
inside your code
StringRequest stringRequest = new StringRequest(Request.Method.POST,
url,new Response.Listener<String>() {})
change it to
StringRequest stringRequest = new StringRequest(Request.Method.PUT, url,
new Response.Listener<String>() {})
add a comment |
inside your code
StringRequest stringRequest = new StringRequest(Request.Method.POST,
url,new Response.Listener<String>() {})
change it to
StringRequest stringRequest = new StringRequest(Request.Method.PUT, url,
new Response.Listener<String>() {})
add a comment |
inside your code
StringRequest stringRequest = new StringRequest(Request.Method.POST,
url,new Response.Listener<String>() {})
change it to
StringRequest stringRequest = new StringRequest(Request.Method.PUT, url,
new Response.Listener<String>() {})
inside your code
StringRequest stringRequest = new StringRequest(Request.Method.POST,
url,new Response.Listener<String>() {})
change it to
StringRequest stringRequest = new StringRequest(Request.Method.PUT, url,
new Response.Listener<String>() {})
edited Nov 15 '18 at 9:40
suresh madaparthi
25219
25219
answered Nov 15 '18 at 9:20
ThunderThunder
2,6052720
2,6052720
add a comment |
add a comment |
Retrofit are more easy to use
On the first screen you'r method are PUT but in your volley request you use POST,try to change to put
add a comment |
Retrofit are more easy to use
On the first screen you'r method are PUT but in your volley request you use POST,try to change to put
add a comment |
Retrofit are more easy to use
On the first screen you'r method are PUT but in your volley request you use POST,try to change to put
Retrofit are more easy to use
On the first screen you'r method are PUT but in your volley request you use POST,try to change to put
answered Nov 15 '18 at 9:13
BenjaminBenjamin
929
929
add a comment |
add a comment |
you must send string instead json
you can send by add to hasmap like:
params.put("ID",id.getText().toString().trim());
params.put("user[Nama]", nama.getText().toString().trim());
params.put("user[Jenis_Kelamin]", jenis_kelamin.getText().toString().trim());
params.put("user[Tgl_Lahir]",tgl_lahir.getText().toString().trim() );
params.put("user[ID_Jabatan]",id_jabatan.getText().toString().trim());
params.put("user[Salary]",salary.getText().toString().trim());
enter code here
Did you check screenshot and the parameter body clearly? That (API) request acceptsapplication/jsonnot form url encoded data. You need to send JSON data.
– Shashanth
Nov 15 '18 at 9:24
add a comment |
you must send string instead json
you can send by add to hasmap like:
params.put("ID",id.getText().toString().trim());
params.put("user[Nama]", nama.getText().toString().trim());
params.put("user[Jenis_Kelamin]", jenis_kelamin.getText().toString().trim());
params.put("user[Tgl_Lahir]",tgl_lahir.getText().toString().trim() );
params.put("user[ID_Jabatan]",id_jabatan.getText().toString().trim());
params.put("user[Salary]",salary.getText().toString().trim());
enter code here
Did you check screenshot and the parameter body clearly? That (API) request acceptsapplication/jsonnot form url encoded data. You need to send JSON data.
– Shashanth
Nov 15 '18 at 9:24
add a comment |
you must send string instead json
you can send by add to hasmap like:
params.put("ID",id.getText().toString().trim());
params.put("user[Nama]", nama.getText().toString().trim());
params.put("user[Jenis_Kelamin]", jenis_kelamin.getText().toString().trim());
params.put("user[Tgl_Lahir]",tgl_lahir.getText().toString().trim() );
params.put("user[ID_Jabatan]",id_jabatan.getText().toString().trim());
params.put("user[Salary]",salary.getText().toString().trim());
enter code here
you must send string instead json
you can send by add to hasmap like:
params.put("ID",id.getText().toString().trim());
params.put("user[Nama]", nama.getText().toString().trim());
params.put("user[Jenis_Kelamin]", jenis_kelamin.getText().toString().trim());
params.put("user[Tgl_Lahir]",tgl_lahir.getText().toString().trim() );
params.put("user[ID_Jabatan]",id_jabatan.getText().toString().trim());
params.put("user[Salary]",salary.getText().toString().trim());
enter code here
answered Nov 15 '18 at 9:16
Hồ Quốc HuyHồ Quốc Huy
86
86
Did you check screenshot and the parameter body clearly? That (API) request acceptsapplication/jsonnot form url encoded data. You need to send JSON data.
– Shashanth
Nov 15 '18 at 9:24
add a comment |
Did you check screenshot and the parameter body clearly? That (API) request acceptsapplication/jsonnot form url encoded data. You need to send JSON data.
– Shashanth
Nov 15 '18 at 9:24
Did you check screenshot and the parameter body clearly? That (API) request accepts
application/json not form url encoded data. You need to send JSON data.– Shashanth
Nov 15 '18 at 9:24
Did you check screenshot and the parameter body clearly? That (API) request accepts
application/json not form url encoded data. You need to send JSON data.– Shashanth
Nov 15 '18 at 9:24
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53315574%2fsend-data-with-json-and-volley%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
Use Retrofit, #notAllHeroesWearACape
– Obsthändler
Nov 15 '18 at 9:08
hey check ur response in postman get error .its Data Base Table error
– suresh madaparthi
Nov 15 '18 at 9:14
how to do that ?
– morten jonathan
Nov 15 '18 at 9:16
open postman first
– suresh madaparthi
Nov 15 '18 at 9:18
google.co.in/…
– suresh madaparthi
Nov 15 '18 at 9:19