Как отправить по HTTP?

Предположим, у меня есть форма, которая сейчас делает сообщение:

<code><form id="post-form" class="post-form" 
      action="/questions/ask/submit" method="post">
</code>

Вы заметите, что нетsite вaction, браузер следует, откуда он получил страницу.

Браузер придерживается текущих правил домена при публикации

<code>If the current page is...                then the browser will POST to
=======================================  =============
http://stackoverflow.com/questions/ask   http://stackoverflow.com/questions/ask/submit
https://stackoverflow.com/questions/ask  https://stackoverflow.com/questions/ask/submit
</code>

Но я хочу убедиться, что браузер всегда будетsecure страница:

<code>http://stackoverflow.com/questions/ask   https://stackoverflow.com/questions/ask/submit
</code>

Обычно вы пытаетесь что-то вроде:

<code><form id="post-form" class="post-form" 
      action="https://stackoverflow.com/questions/ask/submit" method="post">
</code>

За исключением того, что требуется знать домен и виртуальный путь к хост-сайту (например,stackoverflow.com). Если сайт был изменен:

stackoverflow.net stackoverflow.com/mobile de.stackoverflow.com stackoverflow.co.uk/fr beta.stackoverflow.com

тогда формаaction должно быть обновлено также:

<code><form id="post-form" class="post-form" action="https://stackoverflow.net/questions/ask/submit" method="post">

<form id="post-form" class="post-form" action="https://stackoverflow.com/mobile/questions/ask/submit" method="post">

<form id="post-form" class="post-form" action="https://de.stackoverflow.com/questions/ask/submit" method="post">

<form id="post-form" class="post-form" action="https://stackoverflow.co.uk/fr/questions/ask/submit" method="post">

<form id="post-form" class="post-form" action="https://beta.stackoverflow.com/questions/ask/submit" method="post">
</code>

Как я могу поручить браузеру перейти наhttps версияpage?

Гипотетический синтаксис:

<code><form id="post-form" class="post-form" action="https://./questions/ask/submit" method="post">
</code>
302, 303, 307

первоначально302 Found был код, чтобы сказать пользовательскому агенту пойти куда-нибудь еще. Предполагалось, что браузеры просто попробуют еще раз на новом месте:

<code>POST /questions/ask/submit

302 Found
Location: /submitquestion

POST /submitquestion
</code>

К сожалению, все браузеры ошиблись и по ошибке всегда использовалиGET на новом месте:

<code>POST /questions/ask/submit

302 Found
Location: /submitquestion

GET /submitquestion
</code>

Поскольку браузеры ошиблись, были созданы два новых кода:

302 Found: (Legacy deprecated) Try the exact same thing again at the new location; but legacy browsers were switching to GET 303 See Other: Forget whatever the user was doing, and go do a GET on this Location 307 Temporary Redirect: Try the exact same thing again at the new Location (No, seriously, the same thing - i didn't say you could switch to GET. If you were doing a DELETE then go DELETE it over here.)

Например, если пользовательский агент был в серединеPOST:

<code>| Response               | What agent should do  | What many agents actually do |
|------------------------|-----------------------|------------------------------|
| 302 Found              | POST to new Location  | GET from new Location        |
| 303 See Other          | GET from new Location | GET from new Location        |
| 307 Temporary Redirect | POST to new Location  | POST to new Location         |
</code>

В идеале был бы способ использовать307 See Other сказать пользовательскому агенту попробоватьPOST снова на безопасный URL:

<code>POST /questions/ask/submit

302 Found
Location: https://beta.stackoverflow.com/questions/ask/submit

POST /questions/ask/submit
</code>

и я могу обойтись этим достаточно хорошо на стороне сервера в ASP.net:

<code>if (!Request.IsSecureConnection)
{
   string redirectUrl = Request.Url.ToString().Replace("http:", "https:");
   Response.Redirect(redirectUrl);

   //We don't want to send the client the deprecated 302 code, we want to use 307 telling them that we really want them to continue the POST, PUT, DELETE, etc
   Response.StatusCode = (int)System.Net.HttpStatusCode.TemporaryRedirect;     
   Response.End();
}
</code>

Но я не знаю, можете ли вы указать полный URI вLocation.

Ответы на вопрос(2)

Ваш ответ на вопрос