angular.js:12759:选项405(方法不允许)

时间:2017-12-12 06:45:08

标签: javascript angularjs json http-post

我用angular js实现http请求 但是当我传递http请求时不断获取错误代码405方法不允许由于json POST表单数据我使用头文件application / json

 var data_add_cart = {
        service_type : "1",
        product_details : product_array,
        edit_main_id : "0",
        edit_sub_id : "0", 
        api_key: "iZXFJIAFaLVWDx3qmpXuXRnCEsjAU6DZNwt6bEzONAHk4RoRWkyjutho7PQgZlFSYFqEZuspMzubzz0Lg8iXIIQ/t+oyheL4HxGouRJlz8o=",
        log : "",
        language_code: "en",
        branch_id: "1",
        device_type: "android",
        lat : "",
        device_token: "ex7n_U-pwlQ:APA91bGwFupIdjXEJqs4ZtdRwXLPPopDqwIU0gOH5n38ZPFEROk8WdAPQMsBxPLRd_3d8J3qIrUqUp8mEEvUjapCj7LVEOPO3kDt1lGT6r9L1C6VntoYuwbZnstfOSaZxeFXnibJXWKj",
        customer_id: "0",
        device_id: "38fd1dae4605918e",
        app_unique_token : "274AD23D-6F62-4102-A1A9-EAECB5B0491E-android-"+$.now(),
    };

             console.log(JSON.stringify(data_add_cart));
             $http.post('http://URLHERE/api/addtocart/', $httpParamSerializerJQLike(JSON.stringify(data_add_cart)), {
                        headers: {
                                'Content-Type': 'application/json; charset=utf-8',
                                'Accept': 'application/Json'
                        }
                })

我也在.NET(API)方面进行了更改。但是没有得到适当的结果

我已启用CORS,还在网络配置中添加了所有方法 GET POST HEAD PUT < / strong>, OPTION 但仍然收到相同的错误

我遇到错误

-> angular.js:12759 OPTIONS http://URLHERE/api/add_to_cart 405 (Method Not Allowed)

-> Failed to load http://URLHERE/api/add_to_cart: Response for preflight has invalid HTTP status code 405

1 个答案:

答案 0 :(得分:-2)

$ HTTP({   &#39; url&#39;:&#39; http://URLHERE/api/addtocart/&#39;,   &#39;数据&#39;:data_add_cart,   &#39;方法&#39;:&#39; POST&#39;,header:headers})