Node.js在HTTP GET请求中设置标头

时间:2018-03-24 22:05:54

标签: node.js https request-headers

我正在使用Node.js的“https”模块。我发送一个带有一些标题选项的GET请求,但是我收到以下错误:

<!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>

以下是我的代码

 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)
            });
        });

有人可以指导我在设置标题时出错吗?我真的被卡住了。

由于

0 个答案:

没有答案