请求获取错误504

时间:2017-07-27 19:27:46

标签: javascript http server http-status-code-504

所以我们需要发送一个请求,但我们收到错误504,花了几个小时后,我们找不到什么丢失或什么是错误的。 创建它的人已离开,我们无法修复它。完整错误JSON在这里https://pastebin.com/ngumgbEr。请指导我们。

"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;
                });
        });
    };

以下代码是使用上述代码

的示例
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;

0 个答案:

没有答案