Post
Topic
Board Exchanges
Re: Bitstamp Private API signature
by
Last_shot
on 07/02/2014, 22:29:44 UTC
PrintStream is a cause of this issue following code works fine:

private String doPost(String urlString, Map 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;
      

   }