android - How to send json data to server using retrofit? -


i want send json data server in form

{       "comments": "testing",        "quantity": 0,        "retailerid": 0,        "retailerquote": 0,        "subproductid": 999,        "unit": "kg",        "wholesalerid": 999 } 

when posted return "added" response , don't know whats wrong code, it's showing me "method not allowed". how doing it.

hashmap<string,string> header = new hashmap<string, string>();                 header.put("content-type","application/json");                 hashmap<string,string> data = new hashmap<string, string>();                 data.put("comments",comments);                 data.put("quantity",quantity);                 data.put("retailerid",retailerid);                 data.put("retailerquote",retailerquote);                 data.put("wholesalerid",wholesalerid);                 data.put("unit",unit);                 data.put("subproductid",subproductid);                  call<requestquotecheck> call = retrofitbaseadapter.getcommonpathinterfacerequestquote().requestquotecheck(data);                  call.enqueue(new retrofit2.callback<requestquotecheck>() {                      @override                     public void onresponse(call<requestquotecheck> call, response<requestquotecheck> response) {                           toast.maketext(getapplicationcontext(),response.message(),toast.length_short).show();                      }                      @override                     public void onfailure(call<requestquotecheck> call, throwable t) {                      }                 }); 

this base adapter class

    public static webservicemethods getcommonpathinterfacerequestquote() {         final okhttpclient okhttpclient = new okhttpclient.builder()                 .readtimeout(30, timeunit.seconds)                 .connecttimeout(30, timeunit.seconds)                 .build();         retrofit restadapterrequestquote = new retrofit.builder()                 .baseurl(constants.baseurlforrequestquote)                 .addconverterfactory(gsonconverterfactory.create())                 .client(okhttpclient)                 .build();         webservicemethods retrofitinterfaces = restadapterrequestquote.create(webservicemethods.class);         return retrofitinterfaces;     } } 

and webservicemethods.java file

@post("requestquotecheck") call<requestquotecheck> requestquotecheck(         @headermap map<string,string> data ); 

use pass data in gson format instant of passing data in string key value pair.

gradle :-

dependencies {    compile 'com.google.code.gson:gson:2.8.0'   } 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -