java连接zabbix—使用字符串发送请求体

/**
     * zabbix登录
     */
    private static String zabbixLogin(String username, String password, String url) {
        String loginBody = "{\n" +
                "    \"jsonrpc\": \"2.0\",\n" +
                "    \"method\": \"user.login\",\n" +
                "    \"params\": {\n" +
                "        \"user\": " + username + ",\n" +
                "        \"password\": " + password + "\n" +
                "    },\n" +
                "    \"id\": 1,\n" +
                "    \"auth\": null\n" +
                "}";
        String loginResponse = HttpsUtils.sendByHttp(loginBody, url);
        String result = JSON.parseObject(loginResponse).getString("result");
        result = "\"" + result + "\"";
        return result;
    }

你可能感兴趣的:(zabbix,java,zabbix)