我希望将bankname和branchname发送到网址
public interface MInterface { @GET(“/ api / getbank / {银行名称} / {分行名称}”)
void getUser(@Path("bankname") String bankname,@Path("branchname") String branchname, Callback<Pojo> uscb);
}
RestAdapter radapter = new RestAdapter.Builder()。setEndpoint(url).build();
MInterface restInt=radapter.create(MInterface.class);
String bankname="Yes bank";
String branchname="ASSOCIATE COOP BANK UMARWADA";
restInt.getUser(bankname ,branchname ,new Callback<Pojo>() {
@Override
public void success(Pojo model, Response response) {
Data data =model.getData();
String IFSC=data.getIFSC();
Log.d("IFSCHandler","onBankSelected:::"+IFSC);
Toast.makeText(MainActivity.this,IFSC, Toast.LENGTH_LONG).show();
}
@Override
public void failure(RetrofitError error) {
String err = error.getMessage();
}
});
答案 0 :(得分:0)
如果必须使用@GET
,请使用此选项void getUser(@Query("bankname") String bankname,@Query("branchname") String branchname , Callback<Pojo> uscb);
如果你必须使用@POST那么 你必须使用@FormUrlEncoded void getUser(@Field(“bankname”)String bankname,@ Field(“branchname”)String branchname,Callback uscb);
答案 1 :(得分:0)
我希望这会对您有所帮助。
public interface Interface {
//This method is used for "POST"
@FormUrlEncoded
@POST("/api.php")
Call<ServerResponse> post(
@Field("bankname") String bankName,
@Field("branchname") String branchName
);
//This method is used for "GET"
@GET("/api.php")
Call<ServerResponse> get(
@Query("bankname") String bankName,
@Query("branchname") String branchName
);
}
public void getBankDetails(String bankName, String branchName){
//Here a logging interceptor is created
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
//The logging interceptor will be added to the http client
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(logging);
//The Retrofit builder will have the client attached, in order to get connection logs
Retrofit retrofit = new Retrofit.Builder()
.client(httpClient.build())
.addConverterFactory(GsonConverterFactory.create())
.baseUrl(SERVER_URL)
.build();
Interface service = retrofit.create(Interface.class);
Call<ServerResponse> call = service.get(bankName,branchName);
call.enqueue(new Callback<ServerResponse>() {
@Override
public void onResponse(Call<ServerResponse> call, Response<ServerResponse> response) {
BusProvider.getInstance().post(new ServerEvent(response.body()));
Log.e(TAG,"Success");
}
@Override
public void onFailure(Call<ServerResponse> call, Throwable t) {
// handle execution failures like no internet connectivity
BusProvider.getInstance().post(new ErrorEvent(-2,t.getMessage()));
}
});
}
谢谢