Http-Method changes from POST to OPTIONS when changing Content-Type

后端 未结 3 1319
-上瘾入骨i
-上瘾入骨i 2021-01-13 22:27

I am using closure library to do a simple POST. I think XhrIo should work because from my machine when I use any other rest client ,like Firefox browser app RESTClient or Ch

相关标签:
3条回答
  • 2021-01-13 22:37

    If you are pass Content-Type on authorization request it will convert POST method to OPTIONS method so while we are use ouath and passing authorization token that time do not required Content-Type.

    So do not pass Content-Type on all authorization request it won't change your method POST to OPTIONS

    0 讨论(0)
  • 2021-01-13 22:42

    When you add a header to an XHR object, most browsers will do a preflight request, which is the OPTIONS method that you are seeing. There is not a way to circumvent this if you are adding custom headers, unfortunately. The POST will be sent after the OPTIONS.

    This article explains the OPTIONS request a bit. I ran into issues with the preflight a while back, if that is any help.

    If you have specific issues with the OPTIONS request you should edit your question to include them; otherwise, this is expected behavior.

    0 讨论(0)
  • 2021-01-13 22:44

    FWIW mine also failed to update the type when I specified...

    {'content-type':'application/json'}
    

    However, if I corrected the case to

    {'Content-Type':'application/json'}
    

    ... it worked.

    Go figure.

    0 讨论(0)
提交回复
热议问题