question

Lothar avatar image
Lothar asked

Cloudscript externa call

Hi I saw tha is it possible to do http.request via cloudscript.

I look for a method to do a TCP request to my own api. Is it possible via Cloud script?

There is a dedicated apit to do this?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Sarah Zhang avatar image
Sarah Zhang answered

Yes, you can make Http requests from CloudScript to any web API endpoint, using standard REST calls. You can check this documentation -- Making Webhook calls from CloudScript for more details about how to do a web API call from CloudScript. Besides, you can navigate to [Game Manager]->[Automation]->[Cloud Script]->[Revision] to find the following sample in the [Revision 1].

// This is a simple example of making a web request to an external HTTP API.
handlers.makeHTTPRequest = function (args, context) {
    var headers = {
        "X-MyCustomHeader": "Some Value"
    };

    var body = {
        input: args,
        userId: currentPlayerId,
        mode: "foobar"
    };

    var url = "http://httpbin.org/status/200";
    var content = JSON.stringify(body);
    var httpMethod = "post";
    var contentType = "application/json";

    // The pre-defined http object makes synchronous HTTP requests
    var response = http.request(url, httpMethod, content, contentType, headers);
    return { responseContent: response };
};

5 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Lothar avatar image Lothar commented ·

Cool, is it also possible do TCP calls or only http?

0 Likes 0 ·
Sarah Zhang avatar image Sarah Zhang Lothar commented ·

Http calls that based on TCP are OK. It doesn't support the long connection.

0 Likes 0 ·
Lothar avatar image Lothar Sarah Zhang commented ·

I don't need a long connection but to call a mirror server.

0 Likes 0 ·
Show more comments
Lothar avatar image Lothar commented ·

Sorry bad questions

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.