How to POST to HTTPs?

前端 未结 2 1117
旧巷少年郎
旧巷少年郎 2021-01-17 17:59

Assume i have a form that right now is doing a post:

2条回答
  •  不知归路
    2021-01-17 18:20

    you can change the form's action with javascript:

    var form = document.getElementById("post-form");
    form.action = location.href.replace(/^http:/, 'https:');
    

    But there are some security considerations, and I would suggest you to redirect your form's url to https. And although you could do it from javascript, you should never trust javascript when it gets to security, so do it from the server (it's also faster, the page doesn't have to be loaded, only the http header)

提交回复
热议问题