'How to remove last slash "/" from base url in Retrofit 2

When I Type Base Url="https://www.bkashcluster.com:9081/dreamwave/merchant/trxcheck/sendmsg/" with last slash(/) then give me message like this:

Response{protocol=http/1.1, code=500, message=Internal Server Error, url=https://www.bkashcluster.com:9081/dreamwave/merchant/trxcheck/sendmsg/?user=XX&pass=r@12&msisdn=0160000000&trxid=6BM3KRWHLB}

After "sendmsg" slash(/) does not need

And When I Type Base Url="https://www.bkashcluster.com:9081/dreamwave/merchant/trxcheck/sendmsg" with out last slash(/) then apps unfortunately stop;

For this I Want to remove last "/" any way from Base Url.

private void requestDataForBkashTransaction() {
    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl("https://www.bkashcluster.com:9081/dreamwave/merchant/trxcheck/sendmsg/")
            .addConverterFactory(GsonConverterFactory.create())
            .build();


    InstituteService api = retrofit.create(InstituteService.class);

    String urlString=String.format("?user=Exampll&pass=12345&msisdn=0160000000&trxid=6BM3KRWHLB");

    Call<List<Transaction>> call=api.getBkashTrasactionCode(urlString);

    call.enqueue(new retrofit2.Callback<List<Transaction>>() {
        @Override
        public void onResponse(Call<List<Transaction>> call, retrofit2.Response<List<Transaction>> response) {
            if(!response.isSuccessful()){
                Toast.makeText(PaymentActivity.this, response.code(), Toast.LENGTH_LONG).show();
                return;
            }
            List<Transaction> transactions=response.body();
            for(Transaction transaction:transactions){
                String content="";
                content+=transaction.getTrxId();
                textView.append(content);
            }
        }

        @Override
        public void onFailure(Call<List<Transaction>> call, Throwable t) {

        }
    });


}


@GET
Call<List<Transaction>> getBkashTrasactionCode(@Url String url);


Solution 1:[1]

This is not how you add query parameters to a call using retrofit. Response code 500 Internal Server Error indicates that. Please refer to this this and add queries properly, then it should work.

Solution 2:[2]

To remove last slash, you have to remove last path from the baseUrl with ../ first, then append it at your urlStirng instead.

String urlString=String.format("../sendmsg?user=Exampll&pass=12345&msisdn=0160000000&trxid=6BM3KRWHLB");

Solution 3:[3]

First assign your baseUrl to a String variable and remove the last character as below.

String baseUrl = "https://www.bkashcluster.com:9081/dreamwave/merchant/trxcheck/sendmsg/";

if (baseUrl.endsWith("/")) {
    String newBaseUrl = baseUrl.substring(0, baseUrl.length() - 1);
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kuba Paw?owski
Solution 2
Solution 3 LeoN