2017-08-24 53 views
-3

爲什麼下面的代碼不起作用?可能有什麼錯誤的參數?如何使用API​​ post到bityep.com?

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) 
} 
+5

你是什麼意思不工作?它崩潰了嗎?它不是在編譯?它印刷的東西你不指望?任何錯誤消息?請通過編輯您的問題來澄清。謝謝。 – Pang

回答

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) 
} 
+0

它的工作,謝謝! – jackrc