[英]Making a GET request of a JSON RPC API instead of a POST request
是否可以向 JSON RPC API 發出 GET 請求? 我正在嘗試使用 random.org api ( https://api.random.org/json-rpc/1/ ) 來執行此操作。 如果我使用 POST 請求,它可以正常工作,但我需要為我正在處理的應用程序中使用的所有 API 發出 GET 請求。
這是正在運行的發布請求:
function getNewThing(apiUrl) {
data = {
"jsonrpc": "2.0",
"method": "generateIntegers",
"params": {
"apiKey": "key",
"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 編碼:
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'
我錯過了什么? 提前致謝!
NYJS 聚會小組的一些好心人幫助我回答了這個問題。 對於任何碰巧發現這個問題的人:
POST 是您唯一的選擇,因為強烈建議不要使用 GET。 https://www.simple-is-better.org/json-rpc/transport_http.html#get-request http://www.jsonrpc.org/historical/json-rpc-over-http.html#http-header
對於 random.org API,POST 是唯一的選擇https://api.random.org/json-rpc/1/introduction
所有調用都必須通過 HTTP POST 進行。 特別是,不支持 HTTP GET。
注釋:“如果 POST 請求可以作為 GET 請求進行額外處理,這並不完全取決於您和您的實現——這是服務器必須設置才能處理的事情。”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.