title: How to POST to HTTPs?
body: <p>Assume i have a form that right now is doing a post:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;form id="post-form" class="post-form" 
        action="/questions/ask/submit" method="post"&gt;
  </code></pre>
  
  <p>You'll notice there is no <em>site</em> in the <code>action</code>, the browser follows where it got the page from. </p>
  
  <p>The browser follows current domain rules when posting</p>
  
  <pre class="lang-none prettyprint-override"><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></pre>
  
  <p>But I want to ensure that the browser will always go to the <em>secure</em> page:</p>
  
  <pre class="lang-none prettyprint-override"><code>http://stackoverflow.com/questions/ask   https://stackoverflow.com/questions/ask/submit
  </code></pre>
  
  <p>Normally you would try something like:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;form id="post-form" class="post-form" 
        action="https://stackoverflow.com/questions/ask/submit" method="post"&gt;
  </code></pre>
  
  <p>Except that requires knowing the domain and virtual path name of hosting site (e.g. <code>stackoverflow.com</code>). If the site were changed:</p>
  
  <ul>
  <li><code>stackoverflow.net</code></li>
  <li><code>stackoverflow.com/mobile</code> </li>
  <li><code>de.stackoverflow.com</code></li>
  <li><code>stackoverflow.co.uk/fr</code></li>
  <li><code>beta.stackoverflow.com</code></li>
  </ul>
  
  <p>then the form <code>action</code> would have to be updated also:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;form id="post-form" class="post-form" action="https://stackoverflow.net/questions/ask/submit" method="post"&gt;
  
  &lt;form id="post-form" class="post-form" action="https://stackoverflow.com/mobile/questions/ask/submit" method="post"&gt;
  
  &lt;form id="post-form" class="post-form" action="https://de.stackoverflow.com/questions/ask/submit" method="post"&gt;
  
  &lt;form id="post-form" class="post-form" action="https://stackoverflow.co.uk/fr/questions/ask/submit" method="post"&gt;
  
  &lt;form id="post-form" class="post-form" action="https://beta.stackoverflow.com/questions/ask/submit" method="post"&gt;
  </code></pre>
  
  <p>How can I instruct the browser to go to <code>https</code> version of a <strong>page</strong>?</p>
  
  <hr>
  
  <p>Hypothetical syntax:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;form id="post-form" class="post-form" action="https://./questions/ask/submit" method="post"&gt;
  </code></pre>
  
  <h1>302, 303, 307</h1>
  
  <p>Originally <code>302 Found</code> was the code to tell the user agent to go someplace else. The intention was that browsers would simply try again at the new location:</p>
  
  <pre><code>POST /questions/ask/submit
  
  302 Found
  Location: /submitquestion
  
  POST /submitquestion
  </code></pre>
  
  <p>Unfortunately all browsers got it wrong, and would mistakenly always use <code>GET</code> on the new location:</p>
  
  <pre><code>POST /questions/ask/submit
  
  302 Found
  Location: /submitquestion
  
  GET /submitquestion
  </code></pre>
  
  <p>Because browsers got it wrong, two new codes were created:</p>
  
  <ul>
  <li><strong><code>302 Found</code></strong>: <em>(Legacy deprecated)</em> Try the exact same thing again at the new location; but legacy browsers were switching to <code>GET</code></li>
  <li><strong><code>303 See Other</code></strong>: Forget whatever the user was doing, and  go do a <code>GET</code> on this <strong>Location</strong></li>
  <li><strong><code>307 Temporary Redirect</code>:</strong> Try the exact same thing again at the new <strong>Location</strong> (No, seriously, the same thing - i didn't say you could switch to <code>GET</code>. If you were doing a <code>DELETE</code> then go <code>DELETE</code> it over here.)</li>
  </ul>
  
  <p>For example, if the user agent was in the middle of a <code>POST</code>:</p>
  
  <pre><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></pre>
  
  <p>Ideally, there would be a way to use <code>307 Temporary Redirect</code> to tell the user agent to try the <code>POST</code> again on the secure URL:</p>
  
  <pre><code>POST /questions/ask/submit
  
  307 Temporary Redirect
  Location: https://beta.stackoverflow.com/questions/ask/submit
  
  POST /questions/ask/submit
  </code></pre>
  
  <p>and i can get away with that well enough server-side in ASP.net:</p>
  
  <pre><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></pre>
  
  <p>But i don't know if you can specify a full uri in a <code>Location</code>. </p>