WebService 网络请求库 WsNet

码农软件 · 软件分类 · 手机开发包 · 2019-05-04 15:43:07

软件介绍

WsNet 是一个 android WebService 的网络请求库。

添加对应的maven库地址

maven {  
   url "https://raw.githubusercontent.com/zdmisif/WsNet/master"  
}

添加对应的库

dependencies{  
        compile 'com.sandu.develop:wsnet:0.0.1'  
}

三方库使用的简单说明

1.创建Wsnet对象,初始化Webservice的服务名和接入点(用网上查询IP所属地的Webservice作为例子)

Wsnet wsnet = new Wsnet();
wsnet.init("http://WebXml.com.cn/", "http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx");

2.生成一个定义方法的接口类

public interface WsApi {

    @WsMethodName("getCountryCityByIp")
    WsCall getCountryCityByIp(@WsParam("theIpAddress") String theIpAddress);

}

WsMethodName 对应声明对应的方法

WsParam 对应方法的参数

WsFileParam 上传图片的参数,传的是图片数据类型为byte[]

类似Retrofit的用法

3.创建接口对应的一个实体类,调用对应的方法即可

WsApi wsApi = wsnet.create(WsApi.class);
wsApi.getCountryCityByIp("119.132.20.130").execute(new WsCallBack() {
            @Override
            public void onSuccess(String result) {
                //返回的结果数据
            }

            @Override
            public void onFaile(String error) {
                //调用的错误,返回错误信息
            }
        });

PS:目前对返回的数据,都是返回一个字符串,具体返回的数据格式,需要在得到对应的结果数据再进行转换。

本文地址:https://codercto.com/soft/d/5011.html

The Shallows

The Shallows

Nicholas Carr / W. W. Norton & Company / 2011-6-6 / USD 15.95

"Is Google making us stupid?" When Nicholas Carr posed that question, in a celebrated Atlantic Monthly cover story, he tapped into a well of anxiety about how the Internet is changing us. He also crys......一起来看看 《The Shallows》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具