question

Benjamin Bennett avatar image
Benjamin Bennett asked

How do I specific I port in a cloudscript http.request?

var url = "https://myurl.app:80"; // running a digital ocean web app trying to hit port 80
  var method = "post";

  var player = {
    playerid: currentPlayerId,
    value: 100
  };

  var content = JSON.stringify(player);
  var contentBody = content;
  var contentType = "application/json";
  var headers = {};
  headers["Content-Length"] = content.length;

  try
  {
    var responseString = http.request(
      url,
      method,
      contentBody,
      contentType,
      headers
    );
  }
  catch(error)
  {
    log.info(error)
  }


Calling this code returns a cloud script http request error. However if I update the url to

"https://myurl.app" it works fine.

CloudScript
10 |1200

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

Benjamin Bennett avatar image
Benjamin Bennett answered

the myurl.app was a placeholder because the actual URL i wanted to obscure. I did figure out the issue. On DigitalOcean side you have to pass everything through the same port and then fork

10 |1200

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

Dylan avatar image
Dylan answered

http requests use port 80 by default and doesn't need to be specified I believe. Hope this helps :)

10 |1200

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

Sarah Zhang avatar image
Sarah Zhang answered

For clarification, the way you combine the address and port is correct. Could you please clarify is this address “https://myurl.app” your true website address? If so, the reason caused your failure to access the above URL should be the issues of the HTTPS connection.

After researching, we found the “https://myurl.app:80” also can’t be accessed by the browser and the API testing tool -- Postman. Could you please check whether your external port 80 is opened correctly or not, for example, whether the website service you are using has blocked port 80? Or can you try to configure the other ports and test this function with other ports?

10 |1200

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

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.