如何使用API​​发布到bityep.com?

时间:2017-08-24 03:19:53

标签: swift alamofire

为什么下面的代码不起作用?参数可能有问题吗?

let key = "LLLLLXXXXXXZZZZZZKEY"
let nonce = 3
let parameters: Parameters = ["api_key": key, "nonce": nonce]

let data = "method=getInfo&nonce=" + String(nonce)
let sign = generateHMAC(key: key, data: data)

let headers: HTTPHeaders = [
  "Content-Type" : "application/x-www-form-urlencoded",
  "Key": "LLLLLXXXXXXZZZZZZKEY",
  "Sign": sign,
]

Alamofire.request("https://bitye.com/api/1/bid", method: .post, parameters: parameters, headers: headers).response { response in
  debugPrint(response.response)
}

1 个答案:

答案 0 :(得分:0)

那是因为您的请求不正确。根据它的API,它应该是:

let headers: HTTPHeaders = [
  "Content-Type" : "application/json"
]

let parameters: Parameters = [
    "api_key" : "API_KEY",
    "base" : "BTC",
    "counter" : "USD",
    "amount" : "1",
    "price" : "4000.11111"
]

let bidUrl = "https://bityep.com/api/1/bid"

Alamofire.request(bidUrl, method: .post, parameters: parameters, headers: headers).response { response in
  debugPrint(response.response)
}