在Gupshup IDE上发出http Post请求有效吗?

问题描述:

我复制了gupshup的文档代码,并仅将URL修改为" http://posttestserver.com/post.php ",它不起作用.

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

有人对我有建议吗?

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: ""

提前谢谢.

您是否正在使用Gupshup的模拟器进行测试?如果是,则到目前为止,带有标头和参数的POST和GET调用在模拟器中无法正常工作. 文档对此进行了提及.但是,您可以在Facebook Messenger上使用 Gupshup代理机器人部署并测试该代码会很好的工作. 这是我将您的代码直接复制到IDE后进行的测试的屏幕截图.

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.