当我键入Base Url =“ https://www.bkashcluster.com:9081/dreamwave/merchant/trxcheck/sendmsg/”时,最后一个斜杠(/)会给我这样的消息:
响应{协议= http / 1.1,代码= 500,消息=内部服务器错误,网址= {https://www.bkashcluster.com:9081/dreamwave/merchant/trxcheck/sendmsg/?user=XX&pass=r@12&msisdn=0160000000&trxid=6BM3KRWHLB}
“ sendmsg”后的斜杠(/)不需要
当我键入Base Url =“ https://www.bkashcluster.com:9081/dreamwave/merchant/trxcheck/sendmsg”且没有最后一个斜杠(/)时,应用程序将不幸停止;
为此,我想以任何方式从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);
答案 0 :(得分:0)
这不是使用改型向查询中添加查询参数的方式。响应代码500 Internal Server Error指示。请参考此this并正确添加查询,然后它应该可以工作。
答案 1 :(得分:0)
首先将baseUrl分配给String变量,然后删除最后一个字符,如下所示。
String baseUrl = "https://www.bkashcluster.com:9081/dreamwave/merchant/trxcheck/sendmsg/";
if (baseUrl.endsWith("/")) {
String newBaseUrl = baseUrl.substring(0, baseUrl.length() - 1);
}