Actually there are two POST URLs. First POST url is login as follows and even it contains body as json as follows.
String loginUrl = "http://00.00.00.00:0000/url/vs1/login";
json = `{"email": "qqqq@mail.com", "password": "/JGgdwd6vhsvJJFGDF7ttd="}`
Second POST url without payload as follows.
String SiteLoginUrl = "http://00.00.00.00:0000/url/vs1/site/1/login";
So first, above first url need to login then only i can login to second url. Hence first URL is logging in successfully but after getting response i need to login for second URL which doesn't consists of payload or json. So after calling second URL with POST is returning 400 error. For second URL i have written code below.
// java HttpURLConnection for POST without json or payload data
String SiteLoginUrl = "http://00.00.00.00:0000/url/vs1/site/1/login";
HttpURLConnection conn = (HttpURLConnection) new URL(SiteLoginUrl).openConnection();
conn.setDoOutput(true);
conn.setUseCaches(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("ContentType","application/json;charset=UTF-8");
conn.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
JSONObject obj = new JSONObject();
wr.writeBytes(obj.toString()); //String Empty Object
wr.flush();
wr.close();
if(conn.getResponseCode() == HttpURLConnection.HTTP_OK){
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
return 1;
} else {
return 0;
}
In POSTMAN i checked it is working fine (returning successful login response) with text {}
(String Empty Object) payload.