小编Eti*_*may的帖子

对本地主机服务器的简单改造 2 请求

试图制作一个将与使用 noSQL 服务器(app->tomcat->noSQL)的本地主机服务器(tomcat apache)通信的 android 应用程序。我已经设法制作了一个 servlet 来处理“get”方法上的参数并将它们正确加载到数据库中,现在我正在尝试使用retrofit2 lib从我的应用程序插入数据。按照视频和教程,我仍然无法完成这项工作。

这是我正在使用的界面:

public interface APIService {

    @POST("login")
    Call<Boolean> postUser(@Body User user);

    @GET("login")
    Call<Boolean> getUser(@Query("user_email") String user_email,@Query("user_pass") String user_pass);

    public static final Retrofit retrofit = new Retrofit.Builder()
            .baseUrl("http://localhost:8080/")
            .addConverterFactory(GsonConverterFactory.create())
            .build();
}
Run Code Online (Sandbox Code Playgroud)

这是我在应用程序中单击按钮时使用的代码:

APIService ApiService = APIService.retrofit.create(APIService.class);

User user = new User(name, email);
Call<Boolean> call = ApiService.getUser(email,name);
call.enqueue(new Callback<Boolean>() {
    @Override
    public void onResponse(Call<Boolean> call, Response<Boolean> response) {
        String ans = response.message(); //for debugging
        if (ans.compareTo("yes") == 0) {
            Toast.makeText(getApplicationContext(), "YES!", Toast.LENGTH_SHORT).show();
        } else …
Run Code Online (Sandbox Code Playgroud)

java android tomcat nosql retrofit2

6
推荐指数
1
解决办法
8394
查看次数

标签 统计

android ×1

java ×1

nosql ×1

retrofit2 ×1

tomcat ×1