send data with JSON and volley












0















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



enter image description here



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
enter image description here










share|improve this question




















  • 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
















0















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



enter image description here



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
enter image description here










share|improve this question




















  • 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














0












0








0








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



enter image description here



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
enter image description here










share|improve this question
















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



enter image description here



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
enter image description here







java android json android-volley






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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














  • 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












3 Answers
3






active

oldest

votes


















1














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>() {})





share|improve this answer

































    0














    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






    share|improve this answer































      0














      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





      share|improve this answer
























      • 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













      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
      });


      }
      });














      draft saved

      draft discarded


















      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









      1














      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>() {})





      share|improve this answer






























        1














        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>() {})





        share|improve this answer




























          1












          1








          1







          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>() {})





          share|improve this answer















          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>() {})






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 15 '18 at 9:40









          suresh madaparthi

          25219




          25219










          answered Nov 15 '18 at 9:20









          ThunderThunder

          2,6052720




          2,6052720

























              0














              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






              share|improve this answer




























                0














                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






                share|improve this answer


























                  0












                  0








                  0







                  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






                  share|improve this answer













                  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







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 15 '18 at 9:13









                  BenjaminBenjamin

                  929




                  929























                      0














                      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





                      share|improve this answer
























                      • 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


















                      0














                      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





                      share|improve this answer
























                      • 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
















                      0












                      0








                      0







                      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





                      share|improve this answer













                      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






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      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 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



















                      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




















                      draft saved

                      draft discarded




















































                      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.




                      draft saved


                      draft discarded














                      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





















































                      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







                      Popular posts from this blog

                      List item for chat from Array inside array React Native

                      Thiostrepton

                      Caerphilly