我通过Binance交换发​​送HTTP Get请求时遇到麻烦。
(我需要返回我的钱包状态)

GitHub手册上说(https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md




  帐户信息(USER_DATA)
  
  GET / api / v3 / account(HMAC SHA256)
  
  获取当前帐户信息。
  
  重量:5
  
  参数:
  
  名称类型强制说明
  
  recvWindow长号
  
  时间戳记是




我的代码如下所示

    public static String timestamp = String.valueOf(System.currentTimeMillis());

    public static void wallet_status () throws NoSuchAlgorithmException, InvalidKeyException {
    String url = "https://api.binance.com/api/v3/account&timestamp=" + timestamp;

    //sign url
    Mac shaMac = Mac.getInstance("HmacSHA256");
    SecretKeySpec keySpec = new SecretKeySpec(BINANCE_SECRET_KEY.getBytes(), "HmacSHA256");
    shaMac.init(keySpec);
    final byte[] macData = shaMac.doFinal(url.getBytes());
    String sign = Hex.encodeHexString(macData);

    HttpClient client = HttpClientBuilder.create().build();
    HttpGet request = new HttpGet("https://api.binance.com/api/v3/account"+"?timestamp="+timestamp+"?signature="+sign);
    request.addHeader("X-MBX-APIKEY", BINANCE_API_KEY);

    try {
        HttpResponse response = client.execute(request);
        HttpEntity entity = response.getEntity();

        if (entity != null) {
            try (InputStream stream = entity.getContent()) {
                BufferedReader reader =
                        new BufferedReader(new InputStreamReader(stream));
                String line;
                while ((line = reader.readLine()) != null) {
                      System.out.println(line);
                }
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
} //end


服务器响应如下


  {“ code”:-1100,“ msg”:“在参数'timestamp'中发现非法字符;合法范围是'^ [0-9] {1,20} $'。”}


但是我的String时间戳是一个13位数字的字符串,应该没问题。请帮忙。

最佳答案

您的网址错误。将?signature=更改为&signature=

您必须使用&作为URL中后续变量的分隔符。当前,?signature...被视为timestamp变量的值,从而导致该错误消息。

关于java - HttpGet请求与Java Binance交换错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53935798/

10-09 04:26