question

andrewalpha avatar image
andrewalpha asked

http.request POST request from CloudScript not working

Hi,

I'm attempting to make an http.request() call from CloudScript to send a POST API request to an Amazon AWS endpoint.

However, I seem to get HTTP Request Errors like this:

{
    "FunctionResult": null,
    "Logs": [
        {
            "Level": "Error",
            "Message": "HTTP request error",
            "Data": [
                [
                    []
                ],
                [
                    []
                ],
                [
                    []
                ],
                [
                    []
                ],
                [
                    [
                        [
                            []
                        ]
                    ]
                ],
                [
                    [
                        [
                            []
                        ],
                        [
                            []
                        ],
                        [
                            []
                        ],
                        [
                            []
                        ]
                    ]
                ],
                [
                    []
                ]
            ]
        }
    ],
    "ExecutionTimeSeconds": 0.0020326,
    "MemoryConsumedBytes": 11392,
    "APIRequestsIssued": 0,
    "HttpRequestsIssued": 1,
    "Error": {
        "Error": "CloudScriptHTTPRequestError",
        "Message": "The script made an external HTTP request, which returned an error. See the Error logs for details.",
        "StackTrace": "Error\n    at handlers.getReplay (C949-.CloudScript.js:21:25)"
    }
}

I'm able to access my endpoint just fine from Postman.

As an additional test, I tried just accessing https://www.google.com using POST from CloudScript, and it gets the same error as above. Using GET works (for the google test), but I need to use POST for my application.

Is there something I'm doing wrong?

The Title ID in question is C949, at CloudScript revision 563 (yes that's a lot of revisions, please don't laugh).

Thanks!

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.

1 Answer

·
Sarah Zhang avatar image
Sarah Zhang answered

If you can access the endpoint on the Postman successfully. Which content-type is inside the request header? Content-type is the fourth parameter of the http.request. When we test this function using PlayFab API, even if we send an empty string as the content to the endpoint, content-type should be set. If not, "HTTP request error" will appear.

1 comment
10 |1200

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

andrewalpha avatar image andrewalpha commented ·

I had been passing an empty string as content type, but after setting it to an actual value ("application/json") the requests now work perfectly. Thank you Sarah!

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.