retrofit 支持patch请求吗
展开全部
retData;
public void setErrNum(String errNum) {
this.errNum = errNum;
}
public void setErrMsg(String errMsg) {
this.errMsg = errMsg;
}
public WeatherData getRetData() {
return retData;
}
public void setRetData(WeatherData retData) {
this.retData = retData;
}
public String getErrNum() {
return errNum;
}
public String getErrMsg() {
return errMsg;
}
}
public class WeatherData {
private String city; //城市
private String pinyin;//城市拼音
private String citycode; //城市编码
private String date; //日期
private String time;//发布时间
private String postCode; //邮编
private String longitude;//经度
private String latitude; //维度
private String altitude;//海拔
private String weather; //天气情况
private String temp; //气温
private String l_tmp; //最低气温
private String h_tmp; //最高气温
private String WD; //风向
private String WS; //风力
private String sunrise;//日出时间
private String sunset;//日落时间
//setter和getter就不贴了
}
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
新建一个MyService的接口,由于之后要在主线程使用(安卓3.0以上主线程不能同步访问网络),所以这里采用异步获取的方式。故增加了Callback< Result > cb
import retrofit.Callback;
import retrofit.http.GET;
import retrofit.http.Query;
public interface MyService {
// URI:apistore.baidu.com/...eijing
@GET("/microservice/weather")
void getResult(@Query("citypinyin") String citypinyin, Callbackcb);
}12345678910111234567891011
使用RestAdapter来实例化MyService;
import retrofit.RestAdapter;
public class MyRestClient {
private static String API_URL = "apistore.baidu.com/...eijing";
public static MyService getService() {
RestAdapter restAdapter = new RestAdapter.Builder()
.setEndpoint(API_URL)//设置站点路径
.setLogLevel(RestAdapter.LogLevel.FULL)//设置log的级别
.build();
MyService myService = restAdapter.create(MyService.class);
return myService;
}
}123456789101112131415161718123456789101112131415161718
系统调用如下
@Override
public void onStart()
{
super.onStart();
MyRestClient.getService().getResult("beijing",new Callback() {
@Override
public void success(Result result, Response response) {
Log.i("",result.getRetData().getDate());
}
@Override
public void failure(RetrofitError error) {
}
});
}12345678910111213141516171234567891011121314151617
别忘了添加网络访问权限哟。
public void setErrNum(String errNum) {
this.errNum = errNum;
}
public void setErrMsg(String errMsg) {
this.errMsg = errMsg;
}
public WeatherData getRetData() {
return retData;
}
public void setRetData(WeatherData retData) {
this.retData = retData;
}
public String getErrNum() {
return errNum;
}
public String getErrMsg() {
return errMsg;
}
}
public class WeatherData {
private String city; //城市
private String pinyin;//城市拼音
private String citycode; //城市编码
private String date; //日期
private String time;//发布时间
private String postCode; //邮编
private String longitude;//经度
private String latitude; //维度
private String altitude;//海拔
private String weather; //天气情况
private String temp; //气温
private String l_tmp; //最低气温
private String h_tmp; //最高气温
private String WD; //风向
private String WS; //风力
private String sunrise;//日出时间
private String sunset;//日落时间
//setter和getter就不贴了
}
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
新建一个MyService的接口,由于之后要在主线程使用(安卓3.0以上主线程不能同步访问网络),所以这里采用异步获取的方式。故增加了Callback< Result > cb
import retrofit.Callback;
import retrofit.http.GET;
import retrofit.http.Query;
public interface MyService {
// URI:apistore.baidu.com/...eijing
@GET("/microservice/weather")
void getResult(@Query("citypinyin") String citypinyin, Callbackcb);
}12345678910111234567891011
使用RestAdapter来实例化MyService;
import retrofit.RestAdapter;
public class MyRestClient {
private static String API_URL = "apistore.baidu.com/...eijing";
public static MyService getService() {
RestAdapter restAdapter = new RestAdapter.Builder()
.setEndpoint(API_URL)//设置站点路径
.setLogLevel(RestAdapter.LogLevel.FULL)//设置log的级别
.build();
MyService myService = restAdapter.create(MyService.class);
return myService;
}
}123456789101112131415161718123456789101112131415161718
系统调用如下
@Override
public void onStart()
{
super.onStart();
MyRestClient.getService().getResult("beijing",new Callback() {
@Override
public void success(Result result, Response response) {
Log.i("",result.getRetData().getDate());
}
@Override
public void failure(RetrofitError error) {
}
});
}12345678910111213141516171234567891011121314151617
别忘了添加网络访问权限哟。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
Storm代理
2023-07-25 广告
2023-07-25 广告
StormProxies是一家可靠的代理服务提供商,提供原生IP(住宅原生IP)和高匿名代理服务。以下是关于StormProxies的原生IP服务的一些信息:1. 住宅原生IP:StormProxies提供的住宅原生IP是指从真实的家庭或企...
点击进入详情页
本回答由Storm代理提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询