nginx过滤post请求头,POST请求不允许 - 405不允许 - nginx,甚至包括头

I have a problem in trying to do a POST request in my application and I searched a lot, but I did not find the solution.

So, I have a nodeJS application and a website, and I am trying to do a POST request using a form from this site, but I always end up in this:

855a560a724a13fa22eb18d68cb97e0b.png

and in the console I see :

Uncaught TypeError: Cannot read property 'value' of null

Post "http://name.github.io/APP-example/file.html " not allowed

that is in this line of code :

file.html:

Put the emails here...

file.js:

function sendInvitation(){

var teammateEmail= document.getElementById("email").value;

I read many post and a documentation of cross domain but it did not work.

research source 1:http://enable-cors.org/server.html

research source 2: http://www.w3.org/TR/2013/CR-cors-20130129/#http-access-control-max-age

What I am doing now:

I am trying to POST from a different domain of my server :

POST LISTENER : "http://xxx.xxx.x.xx:9000/email , server localhost ( x-> my ip address)

So, I had the same problem in other files, but I fixed it putting this code in the begginning of each route:

var express = require('express');

var sha1 = require('sha1');

var router = express.Router();

var sessionOBJ = require('./session');

var teams = {}

var teamPlayers = []

router.all('*', function(req, res, next) {

res.header("Access-Control-Allow-Origin", "*");

res.header("Access-Control-Allow-Headers", "X-Requested-With");

res.header("Access-Control-Allow-Methods", "PUT, GET,POST");

next();

});

and I fixed it doing it.

Now, I am having the same problem, but in this file the only difference is that I deal with SMTP and emails, so I post an email and send an Email to this email I received in the POST request.

THe code is working totally fine with POSTMAN, so, when I test with POSTMAN it works and I can post.

I included this code below instead of the first one I showed but it did not work as well:

router.all('*', function(req, res, next){

res.header("Access-Control-Allow-Origin", "*")

res.header("Access-Control-Allow-Methods", "POST, GET, OPTIONS")

res.header("Access-Control-Allow-Headers", "Origin, Content-Type, Accept")

res.header("Access-Control-Max-Age", "1728000")

next();

});

Does someone know how to solve it?

Thank you.

解决方案

This configuration to your nginx.conf should help you.

server {

listen 80;

server_name localhost;

location / {

root html;

index index.html index.htm;

}

error_page 404 /404.html;

error_page 403 /403.html;

# To allow POST on static pages

error_page 405 =200 $uri;

# ...

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值