我正在修复一个损坏的项目,并且正在尝试修复其功能之一。
我需要解决使用Retrofit来发布带有数据的帖子,然后接收信息响应的问题。
public interface GetDataService {
@FormUrlEncoded
@POST("pocketdeal/togetallfavorites")
Call<Favourite> getFavorite();
}
获取收藏夹信息的方法
public void MyFavoriteDeals4(String title, String body) {
//(title, body, 1) is the method for adding things
mAPIService.getFavorite().enqueue(new Callback<Post>() {
@Override
public void onResponse(Call<Post> call, Response<Post> response) {
if(response.isSuccessful()) {
showResponse(response.body().toString());
Log.e("Favorites", "Successful");
}
}
@Override
public void onFailure(Call<Post> call, Throwable t) {
Log.e("Favorites", "Failure");
}
});
}
我没有回应或失败,也没有使用我需要的所有信息。此外,在线发布我的API信息是否不好?
我需要使用的信息
我的发帖数据:lat = 37.785834&long = -122.406417&android_id = 1AC7C092-AC45-419F-AFED-3D2FEE473750&timezone = America / Vancouver
我的网址:出于隐私目的删除
请求标头:具有Application / x-www-form-urlencoded的Content-Type
我已经在API测试器中在线测试了所有这些内容,因此我知道,如果操作正确,它会产生正确的结果
在使用@FormUrlEncoded时,应使用Field批注添加参数:
public interface GetDataService {
@FormUrlEncoded
@POST("pocketdeal/togetallfavorites")
Call<Favourite> getFavorite(@Field("lat") Long lat, @Field("long") Long lng, @Field("android_id") String androidId, @Field("timezone") String timezone);
}
您应该像这样初始化改造调用:
Call<Favourite> call2 = favouriteInterfacemAPIService.getFavorite(37.785834, -122.406417, "1AC7C092-AC45-419F-AFED-3D2FEE473750", "America/Vancouver");
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句