PrintStream is a cause of this issue following code works fine:
private String doPost(String urlString, Map<String,String> params) throws IOException, NoSuchAlgorithmException, KeyManagementException {
//"param1=a¶m2=b¶m3=c"
StringBuilder urlParameters = new StringBuilder();
for (String key : params.keySet()) {
if(urlParameters.length() > 0) {
urlParameters.append("&");
}
urlParameters.append(key).append("=").append(URLEncoder.encode(params.get(key)));
}
String query = urlParameters.toString();
URL url = new URL("
https://www.bitstamp.net/api/balance/");
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
//add reuqest header
con.setRequestMethod("POST");
// Send post request
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(query);
wr.flush();
wr.close();
String json = "";
if (con.getResponseCode() == HttpsURLConnection.HTTP_OK) {
BufferedReader br = new BufferedReader(new
InputStreamReader(con.getInputStream()));
String text;
while((text = br.readLine()) != null) {
json += text;
}
br.close();
}else{
;
}
con.disconnect();
System.out.println("Code Response: " + con.getResponseCode());
return json;
}