需要java代码来测试API响应吗?如果API需要身份验证

时间:2016-12-17 11:40:32

标签: java api httpurlconnection api-authorization

目前我正在使用以下代码来获取响应。

public static String LinkCheacker(String URLString) throws IOException {
        String Status;
        try {
            URL url = new URL(URLString);
            HttpURLConnection http = (HttpURLConnection) url.openConnection();
            http.setRequestMethod("GET");
            http.connect();
            Status = http.getResponseCode() + ":" + http.getResponseMessage();
            http.disconnect();
        } catch (Exception e) {
            Status = ":some error:" + e.getMessage();
        }
        return Status;
    }

我有更多的API要通过身份验证进行测试(使用userId,Password登录),我该如何测试它们?请帮帮我。

0 个答案:

没有答案