嘿,大家第一次发布,所以我确定我会错过一些堆栈标准。

无论如何,即使我能够在不运行sql查询的情况下进行连接(如果我取出os.write(queryBody.getBytes(),在我的代码中)),尝试使用Java运行sql查询时仍会收到406错误。我将连接,但是显然无法运行我的sql查询,任何在此的站点都很好,我一直在测试是否在查询中做错了什么,但这似乎是对的。我也尝试了REST客户端,但不支持任何认证连接,下面是相关代码:

            uc.setRequestProperty ("Authorization", basicAuth);
            uc.setRequestMethod("POST");
            uc.setRequestProperty("Accept", "application/json");
            uc.setDoOutput(true);


            String queryBody = "\"query\":{\"match\": {\"tables\": \"\"}}, \"size\": 50";

            OutputStream os = uc.getOutputStream();

            os.write(queryBody.getBytes());
            os.flush();


            Reader reader = new InputStreamReader(uc.getInputStream());
            while (true) {
                int ch = reader.read();
                if (ch==-1) {
                    break;
                }
                System.out.print((char)ch);
            }


我一直在搞乱uc.setRequestProperty行,但是我无法使用它来使其工作。运行uc.getContentType()时,输出为“ application / json; charset = UTF-8”。我已经尝试过其他类似的问题,但无法提出解决方案。

最佳答案

为了解决这个问题,我更改了线路
uc.setRequestProperty(“ Accept”,“ application / json”);

uc.setRequestProperty(“ Content-Type”,“ application / json”);

10-02 04:26
查看更多