LoginSignup
2
1

More than 5 years have passed since last update.

Azure Functions で Post の引数が渡らない問題を検証する

Posted at

Azure Functions の Javascript のディフォールトのプログラムで Post の引数が渡らないので、それを検証しました。

Azure Functions のプログラムです。ディフォールトをメッセージを出すように改造しました。

index.js
module.exports = function (context, req) {
    context.log('JavaScript HTTP trigger function processed a request.');

    if (req.query.name || (req.body && req.body.name)) {
        context.res = {
            // status: 200, /* Defaults to 200 */
            body: "Hello " + (req.query.name || req.body.name) + " " + req.method + "\n"
        };
    }
    else {
        var str_out = ""
        str_out += "*** error ***\n"
        str_out += "method = " + req.method + "\n"
        str_out += "req.body = " + JSON.stringify(req.body) + "\n"
        context.res = {
            status: 400,
            body: str_out
        };
    }
    context.done();
};

まず、Get のテスト

$ curl -G https://ekzemplaro02.azurewebsites.net/api/HttpTriggerJS1?code=****== --
data 'name=jiro'
Hello jiro GET

次に -G を取って Post のテスト

$ curl https://ekzemplaro02.azurewebsites.net/api/HttpTriggerJS1?code=****== --
data 'name=jiro'
*** error ***
method = POST
req.body = "name=jiro"
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1