Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public String query(String path, HashMap<String, String> args) {
- String answer = "";
- try {
- // add nonce and build arg list
- args.put("nonce", String.valueOf(System.currentTimeMillis()));
- String post_data = this.buildQueryString(args);
- String post_data_mac = path + "\0" + post_data;
- // args signature
- Mac mac = Mac.getInstance(SIGN_HASH_FUNCTION);
- SecretKeySpec secret_spec = new SecretKeySpec(Base64.decodeBase64(this.keys.getPrivateKey()), SIGN_HASH_FUNCTION);
- mac.init(secret_spec);
- String signature = Base64.encodeBase64String(mac.doFinal(post_data_mac.getBytes()));
- // build URL
- URL queryUrl = new URL(API_BASE_URL + path);
- // create connection
- HttpURLConnection connection = (HttpURLConnection)queryUrl.openConnection();
- connection.setDoOutput(true);
- // set signature
- connection.setRequestProperty("User-Agent", settings.APP_TITLE);
- connection.setRequestProperty("Rest-Key", this.keys.getApiKey());
- connection.setRequestProperty("Rest-Sign", signature.replaceAll("\n", ""));
- if (connection.getResponseCode() != 200) {
- System.err.println("Failed : HTTP error code : "
- + connection.getResponseCode());
- }
- BufferedReader br = new BufferedReader(new InputStreamReader((connection.getInputStream())));
- String output;
- System.out.println("HTTP response \n");
- while ((output = br.readLine()) != null) {
- System.out.println(output);
- answer+=output;
- }
- connection.disconnect();
- } catch (Exception ex) {
- Logger.getLogger(MtGox.class.getName()).log(Level.SEVERE, null, ex);
- }
- return answer;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement