title: Html Form POST values extracted fine when at localhost:8080 but empty string when deployed at AppSpot Golang
body: <p>Fri 2016.12.09</p>
  
  <p>This simple POST handler will extract form values when running at localhost:8080. [<a href="https://siongui.github.io/2016/03/27/go-server-get-form-post-value/" rel="nofollow noreferrer">1</a>]</p>
  
  <p>However, when deployed to AppSpot, the values are an empty string. Changing the form action to 'GET' works both at localhost:8080 and when deployed at AppSpot.</p>
  
  <p>Tried r.PostFormValue("myValue")  and  r.FormValue("myValue") but both return ""
  r.Method returns "POST" </p>
  
  <p>Even tried adding: enctype="multipart/form-data" to form element</p>
  
  <p>Thank you for looking into this,  Robin</p>
  
  <p><a href="https://siongui.github.io/2016/03/27/go-server-get-form-post-value/" rel="nofollow noreferrer">Golang source</a></p>
  
  <p>Sat 2016.12.10</p>
  
  <p>cont: From GAEfan above</p>
  
  <p>Try:
  r.ParseForm()
  myVal = r.Form["myValue"]</p>
  
  <p>Although the current form Html does validate ttps://validator.w3.org/ I did take the time to be more formal and added the 'type' attribute as suggested.</p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;&lt;meta charset="utf-8"&gt;&lt;title&gt;Get Form POST Value&lt;/title&gt;&lt;/head&gt;
  &lt;body&gt;
    &lt;form method="POST" action="/post" enctype="multipart/form-data"&gt;
      &lt;input type="text" name="myValue" value="qwert"&gt;
      &lt;input type="text" name="email" value="my@email.com"&gt;
      &lt;input type="text" name="data" value="somedata"&gt;
      &lt;button&gt;Send&lt;/button&gt;
    &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The issue seems to be in the response. r.Body is always Nil when deployed at AppSpot.  Even with a    " defer r.Body.Close() "  preceding form value extraction, AppSpot always returns "http: invalid Read on closed Body" Since form values are part of the body response, this would explain why the values are always ""</p>
  
  <p>ref: ttp://www.w3schools.com/tags/ref_httpmethods.asp
  "Note that the query string (name/value pairs) is sent in the HTTP message body of a POST request:"</p>
  
  <pre><code>func postHandler(w http.ResponseWriter, r *http.Request) {
  
    defer r.Body.Close()
  
    fmt.Fprintf(w, "&lt;br&gt;r.FormValue(\"myValue\")  [%s]", r.FormValue("myValue"))
  
    // and the suggestion from earlier
  
    r.ParseForm()
    myVal := r.Form["myValue"]
    fmt.Fprintf(w, "&lt;br&gt;myVal [%s]", myVal)
  
    bod, err := ioutil.ReadAll(r.Body)
    if err != nil {
        fmt.Fprintf(w, "&lt;br&gt;ERROR: ioutil.ReadAll(r.Body):  [%s]", err)
  </code></pre>
  
  <p>Even tried: ttps://cloud.google.com/appengine/docs/go/getting-started/handling-user-input-in-forms but way too complex for their one line of form handling Content: r.FormValue("content")</p>
  
  <p>Thank you for your keen observation on attributes. AppEngine at AppSpot apparently handles matters differently than at localhost, and I have yet to find a suitable tutorial.</p>