Making http Post request on Gupshup IDE works?

2019-08-21 02:27发布

问题:

I copied gupshup's document code and modified just url as "http://posttestserver.com/post.php" and it doesn't work.

Anyone has an advice for me?

else if(event.message.toLowerCase() == "post") {
    var contextParam = {
        "User": {
        "userName": "sbCobxxxx",
        "Password": "xxxxxxx-9f-4307-9d9a-451f3xxxx075",
        "Pin": "16776"
    }
    };
    var url = "http://posttestserver.com/post.php";
    var param = JSON.stringify(contextParam);
    var header = {"Content-Type": "application/json"};
    context.simplehttp.makePost(url, param, header);
}

function HttpResponseHandler(context, event) {
    // if(event.geturl === "http://ip-api.com/json")
    context.sendResponse(event.getresp);
}

Response returns empty string: ""

Thanks in advance.

回答1:

Are you testing using Gupshup's emulator? If yes then POST and GET calls with headers and params doesn't work in the emulator as of now. The documentations mentions it. However, you can deploy the code and test it out using Gupshup proxy bot on Facebook messenger and it will work fine. Here is a screenshot of the testing I did after directly copying your code into the IDE.