我在 python 中有這個可用的 API,如何在 javascript 中重新構建相同的東西?如果不可能,我如何從字體端發送這個 POST 請求?
import requests
gfg_compiler_api_endpoint = "https://ide.geeksforgeeks.org/main.php"
languages = ['C', 'Cpp', 'Cpp14', 'Java', 'Python', 'Python3', 'Scala', 'Php', 'Perl', 'Csharp']
def gfg_compile(lang, code, _input=None, save=False):
data = {
'lang': lang,
'code': code,
'input': _input,
'save': save
}
r = requests.post(gfg_compiler_api_endpoint, data=data)
return r.json()
if __name__ == "__main__":
lang = 'Cpp14'
code = """
#include <iostream>
using namespace std;
int man() {
it a, b;
cin >> a >> b;
cout << (a b);
return 0;
}
"""
_input = "1 5"
print(gfg_compile(lang, code, _input))
uj5u.com熱心網友回復:
您可以使用簡單的xhr請求。
var url = "https://example.com/user";
var xhr = new XMLHttpRequest();
xhr.open("POST", url);
xhr.setRequestHeader("Accept", "application/json");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
console.log(xhr.status);
console.log(xhr.responseText);
}};
var data = `{
"Id": 78912,
"Customer": "Jason Sweet",
"Quantity": 1,
"Price": 18.00
}`;
xhr.send(data);
uj5u.com熱心網友回復:
您可以使用“axios”庫。例如,
axios.post('https:localhost:300/page', {
var1: 'abcd',
var2: '1234'
})
.then(function (response) {
console.log(response);
})
您可以查看他們的檔案,https://axios-http.com/。有大量的 YouTube 視頻對其進行了徹底的解釋。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/385105.html
