Unirest-拼装http请求发送rest接口

public static Integer getInfo(String name) {
        HttpResponse<Integer> httpResponse = null;
        try {
            httpResponse = Unirest.get(url) //url网址
                                    .queryString("sn", serialNumber) //查询参数
                                    .asObject(Integer.class); //返回类型
        } catch (UnirestException e) {
            logger.error(e.getMessage());
            return null;
        }
        if (null == httpResponse || 200 != httpResponse.getStatus()) {
            return null;
        }
        return httpResponse.getBody();
    }

 

posted @ 2016-04-14 11:13  無限大  阅读(1274)  评论(0编辑  收藏  举报