使用retrofit框架
来源:互联网 发布:java平台搭建 编辑:程序博客网 时间:2024/06/03 22:46
普通get请求
@GET("service/getIpInfo.php")
Call<String> getIpInfo(@Query("ip") String ip);参数在body内的post请求
@Headers({"Content-Type: application/json","Accept: application/json"})//需要添加头
@POST("omcApp-web/order/queryOrderList.do?sign=b5f56819de1316305d29d848d89d14e0")
Call<String> getResponseByPostBody(@Body RequestBody route);
参数以键值对的post请求
@POST("mobileLogin")
Call<String> getResponseByPostMaps(@QueryMap Map<String,Object> map);
图片上传
@Multipart
@POST("medical-API/uploadFile/")
Call<String> getUploadImage(@Part("file\"; filename=\"image.jpg")RequestBody imgs);
WebService请求
@Headers({"Content-Type: text/xml","SOAPAction: url"})
@POST("SMS_Service.asmx?op=method")
Call<String> getWeatherbyCityName(@Body String requestEnvelope);
//====================以上是关于网络请求注解的api==================================
Map<String, Object> map = new HashMap<>();
map.put("params","params");
ApiService apiService = initNetWorkConfig().create(ApiService.class);
Call<String> call = apiService.getIpInfo("192.xx.xx.xx");
//postbody
RequestBody body= RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"), jsonParams);
//post图片
RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), file);
//postxml(webServices)
RequestBody body= RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"), xmlParams);
//map转xml
public String getMapToXml(Map<String,String> map,String methName){
String head = "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n";
String ends = "</soap:Envelope>";
StringBuffer stringBuffer = new StringBuffer(head);
stringBuffer.append("<soap:Body>\n");
stringBuffer.append("<" + methName + " xmlns=\"http://tempuri.org/\">\n");
for (Map.Entry<String, String> entry : map.entrySet()) {
stringBuffer.append("<" + entry.getKey() + ">" + entry.getValue() + "</" + entry.getKey() + ">\n");
}
stringBuffer.append("</" + methName + ">\n");
stringBuffer.append("</soap:Body>\n");
stringBuffer.append(ends);
return stringBuffer.toString();
}
====================================以上是传参=====================================
call.enqueue(new Callback<String>() {
@Override
public void onResponse(Call<String> call, Response<String> response) {
//成功回执
}
@Override
public void onFailure(Call<String> call, Throwable t) {
//失败回执
}
});
- Retrofit框架使用笔记
- Retrofit框架基本使用
- 使用retrofit框架
- Retrofit框架的使用
- Retrofit 2.0框架使用。
- Retrofit框架的使用
- retrofit框架使用
- Retrofit网络框架入门使用
- Retrofit+Okhhtp框架使用心得
- android使用retrofit框架示例
- Android网络框架 - Retrofit基本使用
- android网络框架Retrofit使用记录
- 在android中使用Retrofit网络框架
- Android网络请求框架Retrofit使用详解
- 网络请求框架Retrofit的基本使用
- android框架之Retrofit的使用
- Android中retrofit网络请求框架使用
- Retrofit网络请求框架的基本使用
- Weex iOS SDK 集成指南
- Yii2-admin RBAC权限管理的实现
- cmd运行PHP程序
- Linux JDK环境变量设置
- ImportError: libmysqlclient.so.18: cannot open shared object file: No such file or directory
- 使用retrofit框架
- intelliJ idea创建分层的项目结构
- 分布式版本控制系统Git
- mybatis 异常处理:Invalid bound statement (not found)
- 常用排序算法分析(C++实现)
- 类行为和线程处理
- eclipse+tomcat开发web页面遇到问题汇总
- java设计模式——装饰模式(Decorator Pattern)
- BitmapFactory的用法