java - HttpGet 请求 Binance 使用 java 交换错误
问题描述
我在通过 Binance 交换发送 HTTP Get 请求时遇到问题。(我需要返回我的钱包状态)
GitHub手册说(https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md)
帐户信息 (USER_DATA)
获取 /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×tamp=" + 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}$'。"}
但我的字符串时间戳是一个 13 位数字字符串,应该没问题。请帮忙。
解决方案
你的网址是错误的。更改?signature=
为&signature=
。
您必须将其&
用作 URL 中后续变量的分隔符。目前,?signature...
被视为timestamp
变量的值,导致该错误消息。
推荐阅读
- csv - 将元数据从 mp4 提取到 excel
- encryption - 管理服务器集群的 GPG 密钥
- javascript - 如何在 JavaScript 中使用来自 Django 的 {{key}}
- python - 使用单选按钮调用方法
- python - 在 python 中,我无法使用用户输入执行函数
- python-3.x - 在绘制 pandas 数据透视表标题和子标题时合并到 python/pandas
- javascript - 在 request.get 节点调用中获取布尔返回
- c - C 等效于 Python None 类型
- r - R中简单列汇总函数的代码审查
- java - 如何在firestore中获取集合的名称列表?