如何从 localhost (http) 向 django (https) 发送 POST 请求?

How to send POST request from localhost (http) to django (https)?

将所有参数 (header/cookie/post) 作为 docs

发送到代理 /api

并获得

server.js

'use strict';

const fs = require('fs'),
    proxy = require('http-proxy-middleware'),
    browserSync = require('browser-sync').create();

function returnIndexPageFn(req, res, next) {
    res.writeHead(200, {'Content-Type': 'text/html'});
    res.write(fs.readFileSync('./public/app.html'));
    res.end();
    next();
}

browserSync.init({
    port: 88,
    server: {
        baseDir: 'public/',
        index: 'app.html',
        middleware: [
            {route: '/home', handle: returnIndexPageFn},
            proxy(['/api', '/media'], {
                target: 'https://security-site.com',
                logLevel: 'debug',
                changeOrigin: true,
                headers: {
                    Referer: 'https://security-site.com',
                },
            })
        ]
    }
});

我用 angular 5 尝试另一个,但结果相同(((

proxy.conf.json

{
    "/api": {
      "target": "https://security-site.com/",
      "secure": false,
      "changeOrigin": true,
      "logLevel": "info"
    }
}

如何解决这个问题?

我找到了解决方案:

需要将 header Referal 更改为 https 协议

对于browser-sync

server.js

...
    proxy(['/api', '/media'], {
        target: 'https://security-site.com',
        logLevel: 'debug',
        changeOrigin: true,
        headers: {
            Referer: 'https://security-site.com',
        },
    })
...

对于 angular 5 (angular cli): proxy.conf.json

{
    "/api": {
        "target": "https://security-site.com/",
        "headers": {
            "Referer": "https://security-site.com/"
        },
        "secure": false,
        "changeOrigin": true,
        "logLevel": "info"
    }
}