是否可以向JSON RPC API發出GET請求?我正在嘗試使用random.org api(https://api.random.org/json-rpc/1/)來做到這一點。如果我使用POST請求,它會運行,但我需要爲我正在使用的應用程序中使用的所有API發出GET請求。製作JSON RPC API而不是POST請求的GET請求
這裏是POST請求被工作:
function getNewThing(apiUrl) {
data = {
"jsonrpc": "2.0",
"method": "generateIntegers",
"params": {
"apiKey": "9b6ed250-67fc-4afd-b60b-09c6076e5178",
"n": 1,
"min": 0,
"max": 1000000,
"replacement": true,
"base": 10
},
"id": 683489
}
// ajax call to the api
return $.ajax({
type: "POST",
url: apiUrl,
data: JSON.stringify(data),
success: function(result) {
console.log(result)
},
error: function(err) {
console.log(err)
}
});
}
的原因,我認爲這是可以變成一個GET請求,因爲這意味着文檔可以這樣:http://www.jsonrpc.org/historical/json-rpc-over-http.html#encoded-parameters
我試着成立URL沒有運氣以下幾種方式:
用URL編碼的PARAMS:
https://api.random.org/json-rpc/1/invoke?jsonrpc=2.0&method=generateIntegers¶ms=%7B%22apiKey%22%3A%20%229b6ed250-67fc-4afd-b60b-09c6076e5178%22%2C%22n%22%3A%201%2C%22min%22%3A%200%2C%22max%22%3A%201000000%2C%22replacement%22%3A%20true%2C%22base%22%3A%2010%7D&id=683489
沒有:
'https://api.random.org/json-rpc/1/invoke?jsonrpc=2.0&method=generateIntegers¶ms={"apiKey": "9b6ed250-67fc-4afd-b60b-09c6076e5178","n": 1,"min": 0,"max": 1000000,"replacement": true,"base": 10}&id=683489'
我缺少什麼?提前致謝!
每個文檔鏈接出現您需要base64編碼參數 – charlietfl