Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
调用成功时响应正文为空(android)_Android_Asp.net Web Api_Retrofit2 - Fatal编程技术网

调用成功时响应正文为空(android)

调用成功时响应正文为空(android),android,asp.net-web-api,retrofit2,Android,Asp.net Web Api,Retrofit2,请帮忙。我从android在服务器上调用了这个方法,并使用空响应体获得了成功。我的服务器是ASP.NETWebAPI,在android客户端上我使用的是2 方法(路由为“Players/IsParticipant/”): 在安卓系统中: @GET("players/isParticipant") Call<Boolean> isParticipant(@Query("username") String username, @Query("meetingId") int meeting

请帮忙。我从android在服务器上调用了这个方法,并使用空响应体获得了成功。我的服务器是ASP.NETWebAPI,在android客户端上我使用的是2

方法(路由为“Players/IsParticipant/”):

在安卓系统中:

@GET("players/isParticipant")
Call<Boolean> isParticipant(@Query("username") String username, @Query("meetingId") int meetingId);
@GET(“玩家/参与者”)
调用isParticipant(@Query(“username”)字符串username,@Query(“meetingId”)int meetingId);
当我调用它时:

Call<Boolean> call = service.isParticipant("aa", 1);
    call.enqueue(new CustomCallback<Boolean>(this)
    {

        @Override
        public void onSuccess(Boolean model)
        {
            DialogUtils.Show(getApplicationContext(), model.toString());
        }
    });
Call=service.isParticipant(“aa”,1);
enqueue(新的CustomCallback(此)
{
@凌驾
成功时的公共void(布尔模型)
{
DialogUtils.Show(getApplicationContext(),model.toString());
}
});

我得到一个错误,因为模型为空。为什么?我该怎么修呢?如有任何建议,我将不胜感激。

您可以参考以下示例代码:

ASP.NET Web API:

[Route("api/values/getbool/{id:int}/{username}")]
public IHttpActionResult GetBool(int id, string username)
{
    return Ok(true);
}
安卓:

build.gradle文件:

dependencies {
    ...
    compile 'com.squareup.retrofit2:retrofit:2.0.2'
    compile 'com.squareup.retrofit2:converter-gson:2.0.2'
    compile 'com.squareup.retrofit2:converter-scalars:2.0.2'
    ...
}
WebAPIService.java:

public interface WebAPIService {
    ...
    @GET("/api/values/getbool/{id}/{username}")
    Call<Boolean> getBool(@Path("id") int id, @Path("username") String username);
    ...
}

这与我使用(默认)回调时的结果相同,在调用中尝试使用JsonObject而不是Boolean,并在DialogUtils.Show(getApplicationContext(),model.toString())上放置一个断点;
public interface WebAPIService {
    ...
    @GET("/api/values/getbool/{id}/{username}")
    Call<Boolean> getBool(@Path("id") int id, @Path("username") String username);
    ...
}
...
Retrofit retrofit1 = new Retrofit.Builder()
        .baseUrl(API_URL_BASE)
        .addConverterFactory(GsonConverterFactory.create())
        .build();
WebAPIService service1 = retrofit1.create(WebAPIService.class);

Call<Boolean> booleanCall = service1.getBool(1, "user");
booleanCall.enqueue(new Callback<Boolean>() {
    @Override
    public void onResponse(Call<Boolean> call, Response<Boolean> response) {
        Log.i("onResponse", String.valueOf(response.body()));
    }

    @Override
    public void onFailure(Call<Boolean> call, Throwable t) {
        Log.e("onFailure", t.toString());
    }
});
...
05-05 14:10:30.291 15755-15755/com.example.asyncretrofit I/onResponse: true