0

For example, I have Volley code for StringRequest here.

What do we use to achieve the same result for Retrofit and how does interface look like in this case?

        String url = getString(R.string.API_URL) + "/social/revoke-token";

        StringRequest postRequest = new StringRequest
                (Request.Method.POST, url, new Response.Listener<String>() {

                    @Override
                    public void onResponse(String response) {


                        Log.d("RESPONSE FROM SERVER", response.toString());


                    }
                }, new Response.ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError error) {
                        // TODO: Handle error

                    }
                 }){
shire
  • 61
  • 5
  • check this answer: https://stackoverflow.com/a/32621245/6672577 – Shahzad Afridi Jun 15 '19 at 18:42
  • @Opriday And how to use Map for that? What changes would be required in Interface and Retrofit code? – shire Jun 15 '19 at 18:48
  • Can you give me the link of your API so I can try it by myself then will post the code as an answer. I have searched to find the API which gives string response but could not find out. – Shahzad Afridi Jun 15 '19 at 18:50
  • Check this answer also: https://stackoverflow.com/a/40973753/6672577 – Shahzad Afridi Jun 15 '19 at 19:01
  • @Opriday I am creating logout function for facebook. I have to remove accesstoken from the server. So I have to pass fb token, client id, client secret to accomplish that. https://gist.github.com/ashishkharcheiu/ff3203e33562d2fe4842ba9f62d2ffe3 Here is the gist of logout function. http://157.230.83.171 this is the url with endpoint I am using is api/social/revoke-token – shire Jun 15 '19 at 19:45
  • @FormUrlEncoded @POST("url api url") // make sure you give base url to retrofit while makign retrofit object Call logout(@Field("param1") int param1,@Field("param2") int param2); // mention all the parameter which you have puted in map. in retrofit you don't need to attach map so you have to pass those values as parameters to the function. – Shahzad Afridi Jun 15 '19 at 20:01
  • @Opriday also If I don't have model, should i use Call or Call or something other? – shire Jun 15 '19 at 20:31
  • If use ResponseBody then won't need model class for it. – Shahzad Afridi Jun 15 '19 at 20:50

0 Answers0