3

I'm using Node.js 'https' module. And i'm sending a GET request with some headers option but I get the following error:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML>
    <HEAD>
        <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
        <TITLE>ERROR: The request could not be satisfied</TITLE>
    </HEAD>
    <BODY>
        <H1>ERROR</H1>
        <H2>The request could not be satisfied.</H2>
        <HR noshade size="1px"> Bad request.

        <BR clear="all">
        <HR noshade size="1px">
        <PRE> Generated by cloudfront (CloudFront) Request ID: 7H9MBMS_ullYt-ZSpdMw4WjAU0O1QlVaDNw_8QLwlXZa8olpjmRPDQ== </PRE>
        <ADDRESS></ADDRESS>
    </BODY> </HTML>

Following is my code

 const var https = require('https')
 var optionsget = {
                headers: {
                    'client': process.env.MOVIEGLU_CLIENT,
                    'x-api-key': process.env.MOVIEGLUE_API_KEY,
                    'api-version': process.env.MOVIEGLU_API_VERSION,
                    'Authorization': process.env.MOVIEGLUE_AUTHORISATION,
                    'geolocation': user.loc[0] + ';' + user.loc[1],
                    'Content-Type':'application/x-www-form-urlencoded'
                },
                host: process.env.MOVIEGLU_HOST, 
                path: path,
                method: 'GET' 
            };

            // do the GET request
            var content = ''
            var reqGet = https.request(optionsget, function (response) {
                response.on('data', function (data) {
                    // Append data.
                    content += data;
                });
                response.on('end', function () {

                    console.log('content ', content)
                    callback(null, content)
                })
            });
            reqGet.end();
            reqGet.on('error', function (e) {
                callback(e, null)
            });
        });

Can someone please guide me what i'm doing wrong in setting headers? I'm really stuck.

Thanks

  • I think you could have problems with proxy authentication. Keep in mind that 'Authorization' or 'Proxy-Authorization': have a base64 encoding value. If you have user -> myuser and password -> mypassword you should use: "Proxy-Authorization": "Basic YWJlcnR1Y2NpbzpBbmRyZXNfMDAw" – Emeeus May 03 '18 at 17:31
  • please see my solution in below link:-- [https://stackoverflow.com/questions/17121846/node-js-how-to-send-headers-with-form-data-using-request-module/52269311?noredirect=1#comment91486557_52269311](https://stackoverflow.com/questions/17121846/node-js-how-to-send-headers-with-form-data-using-request-module/52269311?noredirect=1#comment91486557_52269311) – Chetna Joshi Sep 11 '18 at 07:17

0 Answers0