Javascript 请求获取错误504
所以我们需要发送一个请求,但我们收到了错误504,在花了几个小时之后,我们无法找到遗漏或错误的地方。 创建它的人已经离开了,我们无法修复它。这里是完整的错误JSON。请引导我们Javascript 请求获取错误504,javascript,http,server,http-status-code-504,Javascript,Http,Server,Http Status Code 504,所以我们需要发送一个请求,但我们收到了错误504,在花了几个小时之后,我们无法找到遗漏或错误的地方。 创建它的人已经离开了,我们无法修复它。这里是完整的错误JSON。请引导我们 "use strict"; exports.__esModule = true; var CryptoJS = require("crypto-js"); var Request = require("request-promise-native"); var ServerRequest = (function () {
"use strict";
exports.__esModule = true;
var CryptoJS = require("crypto-js");
var Request = require("request-promise-native");
var ServerRequest = (function () {
/**
* Class constructor that takes the request data.
* @param authToken is the authorization token for the API.
* @param data RequestData object.
* @param url that should be accessed in the request.
*/
function ServerRequest(authToken, data, url) {
this.authToken = authToken;
this.data = data;
this.url = url;
if (!this.data.get("ad_id")) {
throw new Error("The given data should contain an ad id.");
}
else {
this.getKeyFromData();
this.generateHash();
}
}
/**
* Does the request to the GameHive servers
* @returns {Promise<Object>} Promise object with request response as a JSON object.
*/
ServerRequest.prototype.doRequest = function () {
var _self = this;
return new Promise(function (resolve) {
//* HTTP request options
var options = {
method: "POST",
url: "https://tt2.gamehivegames.com/" + _self.url +
"?d=android&v=1.7.1&time=" + _self.getCurrentTicks() +
"&dummy=78.82546&s=" + _self.hash,
headers: {
"X-HTTP-Method-Override": "POST",
"Accept": "application/vnd.gamehive.btb4-v1.0+json",
"Authorization": "token " + _self.authToken,
"Content-Type": "application/json; charset=UTF-8",
"Host": "tt2.gamehivegames.com",
"Accept-Encoding": "gzip, identity",
"Connection": "Keep-Alive, TE",
"TE": "identity",
"User-Agent": "bestHTTP",
"Content-Length": "99",
},
body: " "
};
Request(options)
.then(function (body) {
resolve(JSON.parse(body));
})
.catch(err => {
console.error(err);
return err;
});
});
};
根据:“504错误通常不是您可以修复的,但需要web服务器或您试图通过的代理进行修复。”你有权访问正在使用的web服务器吗?@Kevin我们也这么认为,但它直到最近才开始工作,创建它的人留下了最新版本。可能是因为你发送了一个内容长度为99、内容类型为json的POST请求,但请求正文是空的。(除非只是为了这个问题而修改)@h“留下最新版本”,你的意思是他们接受了你正在使用的web服务器访问吗?@J.Titus它被设置为JSON,因为我们希望收到JSON返回-我添加了一个使用RequestFrom的示例:“504错误通常不是您可以修复的,但需要web服务器或您试图通过的代理进行修复。“您有权访问您正在使用的web服务器吗?@Kevin我们也这么认为,但它直到最近才开始工作,创建它的人留下了最新版本。可能是因为您发送了一个内容长度为99、内容类型为json的POST请求,但请求正文是空的。(除非只是为了这个问题而修改)@h“留下最新版本”,你的意思是他们接受了你正在使用的web服务器访问吗?@J.Titus它被设置为JSON,因为我们希望收到JSON返回-我添加了一个使用请求的示例
exports.__esModule = true;
var ServerRequest_1 = require("./ServerRequest");
var API = (function () {
function API(adId, playerId, authToken) {
this.adId = adId;
this.playerId = playerId;
this.authToken = authToken;
}
API.prototype.getClanContributions = function () {
return __awaiter(this, void 0, void 0, function () {
var requestUrl, requestData, serverRequest, e_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
requestUrl = "dungeon/contributions";
requestData = new Map();
requestData.set("ad_id", this.adId);
requestData.set("player_id", this.playerId);
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
serverRequest = new ServerRequest_1.ServerRequest(this.authToken, requestData, requestUrl);
return [4 /*yield*/, serverRequest.doRequest()];
case 2: return [2 /*return*/, _a.sent()];
case 3:
e_1 = _a.sent();
console.log("###" + e_1);
return [3 /*break*/, 4];
case 4: return [2 /*return*/];
}
});
});
};
return API;