Android 改装2.0 post请求

Android 改装2.0 post请求,android,api,retrofit2,Android,Api,Retrofit2,您好,我正在尝试使用改装2.0实现Post请求 我的问题是,我应该在onResponse中写入show,以便通过从用户获取输入或手动获取数据 谢谢请求完成后将调用onResponse。您不会以这种相反的顺序请求用户的输入(除非您正在执行多个请求或链接它们)。因此,在提出改装请求之前,您应该已经有了用户的输入 因此,onResponse回调就是处理http响应的地方: @Override public void onResponse(Call<List<Card>

您好,我正在尝试使用改装2.0实现Post请求

我的问题是,我应该在onResponse中写入show,以便通过从用户获取输入或手动获取数据


谢谢

请求完成后将调用onResponse
。您不会以这种相反的顺序请求用户的输入(除非您正在执行多个请求或链接它们)。因此,在提出改装请求之前,您应该已经有了用户的输入

因此,onResponse回调就是处理http响应的地方:

    @Override
    public void onResponse(Call<List<Card>> call, Response<List<Card>> response) {
        processResponse(response.body());
    }
@覆盖
公共void onResponse(调用、响应){
processResponse(response.body());
}
但在发送请求(并接收响应)之前,您可以将表单数据添加到POST请求中,您可以执行以下操作:

@POST("/api/Cards")
Call<List<Card>> createCards(@Body List<Card> cards,
        // Sort the cards using a query string param
        @Query("sort") String contractAccount),
        // Set a group id parameter as the replacement block
        @Path("id") int groupId);
@POST(“/api/Cards”)
调用createCards(@Body List cards,
//使用查询字符串参数对卡片进行排序
@查询(“排序”)字符串(帐户),
//将组id参数设置为替换块
@路径(“id”)int-groupId);

对于post方法,您必须在界面中使用@Body标记

@POST("/api/Cards")
Call<List<Card>> createCards(@Body List<Card> cards);
@POST(“/api/Cards”)
调用createCards(@Body List cards);
和活动中的呼叫

Card card=new Card();
card.setId(20);
card.setTitle("New Cards");
card.setMessage("New Launched cards");

List<Card> cards=new List<Card>();
cards.add(card);
Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(BASE_URL).addConverterFactory(GsonConverterFactory.create())
            .build();

    RequestApi requestApi = retrofit.create(RequestApi.class);
    mCardsRequest = requestApi.createCards(cards);
    mCardsRequest.enqueue(new Callback<List<Card>>() {
        @Override
        public void onResponse(Call<List<Card>> call, Response<List<Card>> response) {
            ** what should I add here to post data **   
        }

        @Override
        public void onFailure(Call<List<Card>> call, Throwable t) {
            //
        }
    });
Card Card=新卡();
卡.setId(20);
卡片。设置标题(“新卡片”);
card.setMessage(“新推出的卡”);
列表卡=新列表();
卡片。添加(卡片);
改装改装=新改装.Builder()
.baseUrl(BASE_URL).addConverterFactory(GsonConverterFactory.create())
.build();
RequestApi RequestApi=reformation.create(RequestApi.class);
mCardsRequest=requestApi.createCards(卡片);
mCardsRequest.enqueue(新回调(){
@凌驾
公共void onResponse(调用、响应){
**我应该在这里添加什么来发布数据**
}
@凌驾
失败时公共无效(调用调用,可丢弃的t){
//
}
});

您在哪里调用
createCards()
?您可能希望将
明信片
移动到加载器对象中,因为您的响应可能到达较旧的活动实例,并在处理过程中导致内存泄漏。您能否解释如何that@IgorGanapolskyput Log.d(“tags”,t.toString);在onFailure方法中,并告诉我错误