0

I have a asp.net web api url which accepts query string parameters but its actually a post request. I am trying to access the same url in android but not sure how to pass the query parameters. Any help will be appreciated as I am not an android developer basically.

Here is the snippet:

     RequestBody formBody = new FormBody.Builder()
                    .add("email", mEmail.toLowerCase())
                    .add("password", mPassword)
                    .build();

            //2. Bind the request Object
            Request req = new Request.Builder()
                    .url(loginAPI).post(formBody)
                    .build();
            Response response = client.newCall(req).execute();
sai1990
  • 5
  • 6
  • Follow this link, some answer may help you https://stackoverflow.com/questions/24233632/how-to-add-parameters-to-api-http-post-using-okhttp-library-in-android – King of Masses Sep 22 '17 at 04:57
  • I have already referred these websites.I am unable to come to find a solution – sai1990 Sep 22 '17 at 05:00

1 Answers1

0

This is the solution:

String loginAPI = "http://api.myapi.com/api/authentication?email="+mEmail.toLowerCase()+"&password="+mPassword;

            RequestBody reqbody = RequestBody.create(null, new byte[0]);
           Request  req = new Request.Builder()
                    .url(loginAPI)
                    .method("POST", reqbody)
                    .build();

            Response response = client.newCall(req).execute();
sai1990
  • 5
  • 6