Axios PUT options ok, but not doing the real call (POST does work)












1














Am a bit confused about what is happening here. I have done all my CORS research and made it work with my POST and GET request, that is all fine and shining. But now I needed a PUT request (cause put stands for update). And my OPTIONS request is all fine but it is not doing the real call. If i change the methods to POST, in laravel and Axios (in VueJs), it works. Anyone has a clue, here is my response from server:



enter image description here



Versions:




  • Axios - 0.18.0 (latest release)


Any more information required, let me know and I will try my best to provide that.



UPDATE: sorry i made a typo in my last sentence: "If i change the methods to PUT, in laravel and Axios (in VueJs), it works"



Methods should be POST not PUT, so like this: "If i change the methods to POST, in laravel and Axios (in VueJs), it works"










share|improve this question
























  • Do the PUT method is allowed for this route in laravel. If you use Laravel-cors check if the method is allowed too.
    – Core972
    Nov 19 '18 at 15:30










  • @Core972 isnt the 'Allow: PUT' more then enough to know? and if it wasnt allowed, should the status code not have been 200 but 400?
    – Niels Lucas
    Nov 19 '18 at 15:35












  • That's the response to the OPTIONS call which tells the client what's allowed in the CORS request. It will not send a 400 error because it does not yet know what request you intend to do. The browser will just not make the request unless it's a PUT request. All CORS security checks are imposed client-side
    – apokryfos
    Nov 19 '18 at 15:54












  • Did you create routes for both the options and the put request? I had a similar issue not too long ago
    – mur762
    Nov 19 '18 at 19:34










  • @mur762 options should not be a route method. Its just a cors thing. I do know that it is possible to create a options route in laravel, but i have not really looked into it. But it works now, see my own answer
    – Niels Lucas
    Nov 20 '18 at 8:56
















1














Am a bit confused about what is happening here. I have done all my CORS research and made it work with my POST and GET request, that is all fine and shining. But now I needed a PUT request (cause put stands for update). And my OPTIONS request is all fine but it is not doing the real call. If i change the methods to POST, in laravel and Axios (in VueJs), it works. Anyone has a clue, here is my response from server:



enter image description here



Versions:




  • Axios - 0.18.0 (latest release)


Any more information required, let me know and I will try my best to provide that.



UPDATE: sorry i made a typo in my last sentence: "If i change the methods to PUT, in laravel and Axios (in VueJs), it works"



Methods should be POST not PUT, so like this: "If i change the methods to POST, in laravel and Axios (in VueJs), it works"










share|improve this question
























  • Do the PUT method is allowed for this route in laravel. If you use Laravel-cors check if the method is allowed too.
    – Core972
    Nov 19 '18 at 15:30










  • @Core972 isnt the 'Allow: PUT' more then enough to know? and if it wasnt allowed, should the status code not have been 200 but 400?
    – Niels Lucas
    Nov 19 '18 at 15:35












  • That's the response to the OPTIONS call which tells the client what's allowed in the CORS request. It will not send a 400 error because it does not yet know what request you intend to do. The browser will just not make the request unless it's a PUT request. All CORS security checks are imposed client-side
    – apokryfos
    Nov 19 '18 at 15:54












  • Did you create routes for both the options and the put request? I had a similar issue not too long ago
    – mur762
    Nov 19 '18 at 19:34










  • @mur762 options should not be a route method. Its just a cors thing. I do know that it is possible to create a options route in laravel, but i have not really looked into it. But it works now, see my own answer
    – Niels Lucas
    Nov 20 '18 at 8:56














1












1








1







Am a bit confused about what is happening here. I have done all my CORS research and made it work with my POST and GET request, that is all fine and shining. But now I needed a PUT request (cause put stands for update). And my OPTIONS request is all fine but it is not doing the real call. If i change the methods to POST, in laravel and Axios (in VueJs), it works. Anyone has a clue, here is my response from server:



enter image description here



Versions:




  • Axios - 0.18.0 (latest release)


Any more information required, let me know and I will try my best to provide that.



UPDATE: sorry i made a typo in my last sentence: "If i change the methods to PUT, in laravel and Axios (in VueJs), it works"



Methods should be POST not PUT, so like this: "If i change the methods to POST, in laravel and Axios (in VueJs), it works"










share|improve this question















Am a bit confused about what is happening here. I have done all my CORS research and made it work with my POST and GET request, that is all fine and shining. But now I needed a PUT request (cause put stands for update). And my OPTIONS request is all fine but it is not doing the real call. If i change the methods to POST, in laravel and Axios (in VueJs), it works. Anyone has a clue, here is my response from server:



enter image description here



Versions:




  • Axios - 0.18.0 (latest release)


Any more information required, let me know and I will try my best to provide that.



UPDATE: sorry i made a typo in my last sentence: "If i change the methods to PUT, in laravel and Axios (in VueJs), it works"



Methods should be POST not PUT, so like this: "If i change the methods to POST, in laravel and Axios (in VueJs), it works"







laravel vue.js axios






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 16:01

























asked Nov 19 '18 at 15:23









Niels Lucas

72113




72113












  • Do the PUT method is allowed for this route in laravel. If you use Laravel-cors check if the method is allowed too.
    – Core972
    Nov 19 '18 at 15:30










  • @Core972 isnt the 'Allow: PUT' more then enough to know? and if it wasnt allowed, should the status code not have been 200 but 400?
    – Niels Lucas
    Nov 19 '18 at 15:35












  • That's the response to the OPTIONS call which tells the client what's allowed in the CORS request. It will not send a 400 error because it does not yet know what request you intend to do. The browser will just not make the request unless it's a PUT request. All CORS security checks are imposed client-side
    – apokryfos
    Nov 19 '18 at 15:54












  • Did you create routes for both the options and the put request? I had a similar issue not too long ago
    – mur762
    Nov 19 '18 at 19:34










  • @mur762 options should not be a route method. Its just a cors thing. I do know that it is possible to create a options route in laravel, but i have not really looked into it. But it works now, see my own answer
    – Niels Lucas
    Nov 20 '18 at 8:56


















  • Do the PUT method is allowed for this route in laravel. If you use Laravel-cors check if the method is allowed too.
    – Core972
    Nov 19 '18 at 15:30










  • @Core972 isnt the 'Allow: PUT' more then enough to know? and if it wasnt allowed, should the status code not have been 200 but 400?
    – Niels Lucas
    Nov 19 '18 at 15:35












  • That's the response to the OPTIONS call which tells the client what's allowed in the CORS request. It will not send a 400 error because it does not yet know what request you intend to do. The browser will just not make the request unless it's a PUT request. All CORS security checks are imposed client-side
    – apokryfos
    Nov 19 '18 at 15:54












  • Did you create routes for both the options and the put request? I had a similar issue not too long ago
    – mur762
    Nov 19 '18 at 19:34










  • @mur762 options should not be a route method. Its just a cors thing. I do know that it is possible to create a options route in laravel, but i have not really looked into it. But it works now, see my own answer
    – Niels Lucas
    Nov 20 '18 at 8:56
















Do the PUT method is allowed for this route in laravel. If you use Laravel-cors check if the method is allowed too.
– Core972
Nov 19 '18 at 15:30




Do the PUT method is allowed for this route in laravel. If you use Laravel-cors check if the method is allowed too.
– Core972
Nov 19 '18 at 15:30












@Core972 isnt the 'Allow: PUT' more then enough to know? and if it wasnt allowed, should the status code not have been 200 but 400?
– Niels Lucas
Nov 19 '18 at 15:35






@Core972 isnt the 'Allow: PUT' more then enough to know? and if it wasnt allowed, should the status code not have been 200 but 400?
– Niels Lucas
Nov 19 '18 at 15:35














That's the response to the OPTIONS call which tells the client what's allowed in the CORS request. It will not send a 400 error because it does not yet know what request you intend to do. The browser will just not make the request unless it's a PUT request. All CORS security checks are imposed client-side
– apokryfos
Nov 19 '18 at 15:54






That's the response to the OPTIONS call which tells the client what's allowed in the CORS request. It will not send a 400 error because it does not yet know what request you intend to do. The browser will just not make the request unless it's a PUT request. All CORS security checks are imposed client-side
– apokryfos
Nov 19 '18 at 15:54














Did you create routes for both the options and the put request? I had a similar issue not too long ago
– mur762
Nov 19 '18 at 19:34




Did you create routes for both the options and the put request? I had a similar issue not too long ago
– mur762
Nov 19 '18 at 19:34












@mur762 options should not be a route method. Its just a cors thing. I do know that it is possible to create a options route in laravel, but i have not really looked into it. But it works now, see my own answer
– Niels Lucas
Nov 20 '18 at 8:56




@mur762 options should not be a route method. Its just a cors thing. I do know that it is possible to create a options route in laravel, but i have not really looked into it. But it works now, see my own answer
– Niels Lucas
Nov 20 '18 at 8:56












1 Answer
1






active

oldest

votes


















0














Ok, so I had to put a header for allowing the PUT method:



header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: *");
header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE"); <----


First I did not had that header, but my GET and POST worked fine, so default header is set for only GET/POST maybe? Now I defined all the methods by myself and now it is working. I know this can be better done in Laravel with a cors package or make an middleware, but I will do that in the future. For now this works.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53377743%2faxios-put-options-ok-but-not-doing-the-real-call-post-does-work%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Ok, so I had to put a header for allowing the PUT method:



    header("Access-Control-Allow-Origin: *");
    header("Access-Control-Allow-Headers: *");
    header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE"); <----


    First I did not had that header, but my GET and POST worked fine, so default header is set for only GET/POST maybe? Now I defined all the methods by myself and now it is working. I know this can be better done in Laravel with a cors package or make an middleware, but I will do that in the future. For now this works.






    share|improve this answer


























      0














      Ok, so I had to put a header for allowing the PUT method:



      header("Access-Control-Allow-Origin: *");
      header("Access-Control-Allow-Headers: *");
      header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE"); <----


      First I did not had that header, but my GET and POST worked fine, so default header is set for only GET/POST maybe? Now I defined all the methods by myself and now it is working. I know this can be better done in Laravel with a cors package or make an middleware, but I will do that in the future. For now this works.






      share|improve this answer
























        0












        0








        0






        Ok, so I had to put a header for allowing the PUT method:



        header("Access-Control-Allow-Origin: *");
        header("Access-Control-Allow-Headers: *");
        header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE"); <----


        First I did not had that header, but my GET and POST worked fine, so default header is set for only GET/POST maybe? Now I defined all the methods by myself and now it is working. I know this can be better done in Laravel with a cors package or make an middleware, but I will do that in the future. For now this works.






        share|improve this answer












        Ok, so I had to put a header for allowing the PUT method:



        header("Access-Control-Allow-Origin: *");
        header("Access-Control-Allow-Headers: *");
        header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE"); <----


        First I did not had that header, but my GET and POST worked fine, so default header is set for only GET/POST maybe? Now I defined all the methods by myself and now it is working. I know this can be better done in Laravel with a cors package or make an middleware, but I will do that in the future. For now this works.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 20 '18 at 8:24









        Niels Lucas

        72113




        72113






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53377743%2faxios-put-options-ok-but-not-doing-the-real-call-post-does-work%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            Origin of the phrase “under your belt”?