Axios PUT options ok, but not doing the real call (POST does work)
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:
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
add a comment |
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:
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
Do thePUT
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 theOPTIONS
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 aPUT
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
add a comment |
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:
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
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:
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
laravel vue.js axios
edited Nov 19 '18 at 16:01
Niels Lucas
asked Nov 19 '18 at 15:23
Niels LucasNiels Lucas
721113
721113
Do thePUT
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 theOPTIONS
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 aPUT
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
add a comment |
Do thePUT
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 theOPTIONS
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 aPUT
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
add a comment |
1 Answer
1
active
oldest
votes
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.
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 20 '18 at 8:24
Niels LucasNiels Lucas
721113
721113
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 aPUT
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