Search code examples
djangohttphttpsproxydjango-csrf

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


Send to proxy /api with all params (header/cookie/post) as docs

PrtScreen with request param (header/cookie/post)

And get

PrtScreen with response 403 Forbidden

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',
                },
            })
        ]
    }
});

I try another with angular 5, but have the same result(((

proxy.conf.json

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

How to solve this problem?


Solution

  • I find solution:

    Need change header Referal to https protocol

    For browser-sync

    server.js

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

    For 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"
        }
    }