javascript - Request header field Access-Control-Request-Methods is not allowed by Access-Control-Allow-Headers in preflight response -


i'm trying send post request website remote server encounter cors issues.

i searched in internet didn't find solution specific problem. ajax request params:

var params = {     url: url,     method: 'post',     data: json.stringify(data),     contenttype: 'json',     headers: {         'access-control-request-origin': '*',         'access-control-request-methods': 'post'     } 

on backend side in code in python:

@app.route(settings_namespace + '/<string:product_name>', methods=['post', 'options']) @graphs.time_method()  def get_settings(product_name):     settings_data = helper.param_validate_and_extract(request, none, required=true, type=dict, post_data=true)     settings_data = json.dumps(settings_data)     response = self._get_settings(product_name, settings_data)     return output_json(response, requests.codes.ok, headers = {         'access-control-allow-origin': '*',          'access-control-allow-methods': 'post'     }) 

i error on console:

xmlhttprequest cannot load [http://path-to-my-server]. request header field access-control-request-methods not allowed access-control-allow-headers in preflight response

i did notice can add 'access-control-request-headers' wasn't sure if necessary , cause me more problems removed it.

does know how solve problem?

your ajax request shouldn't send access-control headers, server sends headers allow servers describe set of origins permitted read information using web browser.

the same-origin policy doesn't apply outside browsers, server has send cors headers or jsonp data if browser going able data.

the browser doesn't send headers server, doesn't have to, it's server decides whether or not data available specific origin.

remove header option params object, , should work


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -