我得到了 - error = "Invalid API key/secret pair.";
但是在Swift with Alamofire中我尝试做同样的请求并得到错误......
我的代码:
func getRawJSON(method: String) {
let publicKey = "YF9RCYRE-GL29DI0T-8GE62O2X-9OQ21A2P"
let secretKey = "79aef0ae2bb54df5c5a4e6c28757ddf54a184964fb8c978b5770895944ca7778b582ff390dffdf073a77aac1de1ea1a793dfa6629c3394465345d31a62f953e9"
let APIURL = "https://www.poloniex.com/tradingApi"
let timeNowInt = Int(NSDate().timeIntervalSince1970)
let timeNow = String(timeNowInt)
let query = NSURLComponents()
query.queryItems = [NSURLQueryItem(name: "command", value: method) as URLQueryItem,
NSURLQueryItem(name: "nonce", value: timeNow) as URLQueryItem]
let requestString = query.query!
let params = [
"command": method,
"nonce:": timeNowInt
] as [String : Any]
let codering = requestString.hmac(algorithm: .SHA512, key: secretKey)
let headers = [
"Sign": codering,
"Key": publicKey,
"Content-Type":"application/x-www-form-urlencoded"] as [String : String]
print(headers)
Alamofire.request(APIURL, withMethod: .post, parameters: params, encoding: .url, headers: headers)
.responseJSON { response in
print(response)
}
}