Reputation: 11
Hey everyone first time posting so I'm sure I'll miss some stack standards.
Anyways I'm getting a 406 error when attempting to run a sql query with java, even though I'm able to connect without running the sql query (in my code if I take out os.write(queryBody.getBytes()); I will connect, but obviously can't run my sql query. Any insite on this would be great, I've been testing to see if I did something wrong in my query but it seems to be right. I've also tried REST client but it doesn't support no certification connection. Here is the relevant code:
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);
}
I've been messing around with the line uc.setRequestProperty, but I'm unable to get it working using that. My output when I run uc.getContentType() is "application/json; charset=UTF-8". I've tried the other similar questions on stack but wasn't able to come up with a solution.
Upvotes: 0
Views: 145
Reputation: 11
To fix this issue I changed the line uc.setRequestProperty("Accept", "application/json"); To uc.setRequestProperty("Content-Type", "application/json");
Upvotes: 1