KiteRequest.java 文件源码

java
阅读 20 收藏 0 点赞 0 评论 0

项目:javakiteconnect 作者:
/**
 * GET request using UniRest library without params.
 * @param url is endpoint to which request has to be done.
 * @return JSONObject returns json response.
 * @throws KiteException contains error message and error code inside.
 * @throws JSONException occurs when there is error while parsing data.
 */
public JSONObject getRequest(String url) throws KiteException, JSONException {

    try {
        if(KiteConnect.httpHost != null){
            Unirest.setProxy(KiteConnect.httpHost);
        }
        HttpResponse<JsonNode> response = Unirest.get(url)
                .header("accept", "application/json")
                .asJson();

        JsonNode body = response.getBody();
        JSONObject jsonObject = body.getObject();
        int code = response.getStatus();

        if (code == 200)
            return jsonObject;
        else
            throw dealWithKiteException(body, code);

    } catch (UnirestException e) {
        throw new KiteNoNetworkException("Connection error");
    }

}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号