Making http Post request on Gupshup IDE works?

北战南征 提交于 2020-01-06 05:28:06

问题


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.



来源:https://stackoverflow.com/questions/45134776/making-http-post-request-on-gupshup-ide-works

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!