0

Even after installing CORS middle ware and enabling Cross Origin Requests also. I am unable to make a post request by using Javascript.

const csrf = Cookies.get('csrftoken');
    return {
    'X-CSRFToken' : csrf,
    'Access-Control-Allow-Origin':"*"
    "Access-Control-Allow-Headers":"Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers"};

And also in Django app

CORS_ORIGIN_ALLOW_ALL = True
CORS_ORIGIN_WHITELIST = (
'127.0.0.1',
)

CORS_ALLOW_HEADERS = (
'x-requested-with',
'content-type',
'accept',
'origin',
'authorization',
'x-csrftoken',
'x-api-key'
)

And also after adding CORS Middleware,

MIDDLEWARE_CLASSES = ('corsheaders.middleware.CorsMiddleware')
Yasel
  • 2,920
  • 4
  • 40
  • 48
TARUN KUMAR
  • 141
  • 8

1 Answers1

0

Maybe you need to set Access-Control-Request-Methods. Something like this

"Access-Control-Request-Methods": "OPTIONS, HEAD, GET, POST"

Check this question Default value for Access-Control-Request-Methods

Community
  • 1
  • 1
wilcus
  • 739
  • 1
  • 7
  • 17
  • I am getting like this when making a post request ... `Request header field access-control-allow-origin is not allowed by Access-Control-Allow-Headers in preflight response.` – TARUN KUMAR Oct 26 '16 at 05:44