0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【node.js】lambdaからベーシック認証がかかったサイトへGETリクエストを送る

Last updated at Posted at 2019-04-26

AWS lambdaからステージング環境にGETリクエストを送信したかったのですが、ベーシック認証がかかっていて、なかなか苦労しました。。。

以下で動いてくれましたので、お試しくださいね!

環境

ランタイム ハンドラ
Node.js 8.10 index.handler

コード

node.js
exports.handler = function index(event, context, callback) {
    const util = require('util');
    const http = require('https');

    const host = '****URL****';         // e.g. test.com
    const path = '****/TO/TARGET****';  // e.g. /user/dashboard
    const user = '****USERNAME****';
    const pwd  = '****PASSWORD****';

    const req = http.get(
        {
            "host"  : host,
            "path"  : path,
            "auth"  : user + ":" + pwd,
        },
        function(res) {
            console.log("[info] Status Code: " + res.statusCode);
            console.log("[info] res:" + util.inspect(res, false, null));
        },
    );
    req.on('error', function(e){
        console.log("[error] " + util.inspect(e, false, null));
    });
};
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?