title: Post request to Golang API to send JSON and stringy-fied JSON
body: <p>While making a <code>POST</code> request to Golang API, if I send stringy-fied <code>JSON</code> data it returns success but when I send <code>JSON</code> data it returns error with <code>status 403</code>.</p>
  
  <p>Please help me understanding this behavior and how can I send <code>JSON</code> data using a <code>POST</code> request method.</p>
  
  <p>File: main.go</p>
  
  <pre><code>package main
  
  import (
      "devmgmtv2/auth"
      "github.com/gorilla/handlers"
      "github.com/gorilla/mux"
      "log"
      "net/http"
  )
  
  func main() {
      router := mux.NewRouter()
      auth.AuthInit(router)
      ssid.SsidInit(router)
      headersOk := handlers.AllowedHeaders([]string{"X-Requested-With"})
      originsOk := handlers.AllowedOrigins([]string{"*"})
      methodsOk := handlers.AllowedMethods([]string{"GET", "HEAD", "POST", "PUT", "OPTIONS"})
      router.HandleFunc("/auth/login", Login).Methods("POST", "OPTIONS")
      log.Fatal(http.ListenAndServe(":8000", handlers.CORS(headersOk, originsOk, methodsOk)(router)))
  }
  
  func Login(w http.ResponseWriter, r *http.Request) {
      //Create User Struct
      var user User
      json.NewDecoder(r.Body).Decode(&amp;user)
      userPassword := getUserPassword(user.User)
      // call get value for that user
      // check for equality if true, return the structure
      // if false return error
      if user.Password == userPassword {
          w.Header().Set("Content-Type", "text/plain")
          w.Write([]byte("success"))
      } else {
          http.Error(w, "Forbidden", http.StatusForbidden)
      }
  }
  </code></pre>