I have below code for getting access token. I am getting response status as 400 and response message as "BAD REQUEST". public String getSessionKey(){ BufferedReader rd = null; StringBuilder sb = null; StringBuilder stringBuilder = new StringBuilder(); try { URL url = new URL("https://api.kite.trade/session/token");
int status = conn.getResponseCode(); System.out.println(conn.getResponseMessage()); switch (status) { case 200: case 201: BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
Logically, this looks correct. Any API related error should come back with a JSON response (including an error message). If you're not getting a JSON response, the POST request you making may be problematic in itself.
Rajesh
Ex:
URL url = new URL("https://api.kite.trade/session/token?api_key=&request_token="+request_token+"&checksum="+sha256hex);
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.connect();
int status = conn.getResponseCode();