title: http.Post data-binary, curl equivalent in golang
body: <p>I'm trying to use net/http to post a json file to ElasticSearch.  Normally in Curl I would do the following:</p>
  
  <pre><code>curl -XPOST localhost:9200/prod/aws -d @aws.json
  </code></pre>
  
  <p>In golang I've used an example but it has not worked.  I can see it posting but something must be set incorrectly.  I've tested the JSON file I am using and it's good to go.</p>
  
  <p>Go code:</p>
  
  <pre><code>  target_url := "http://localhost:9200/prod/aws"
    body_buf := bytes.NewBufferString("")
    body_writer := multipart.NewWriter(body_buf)
    jsonfile := "aws.json"
    file_writer, err := body_writer.CreateFormFile("upfile", jsonfile)
    if err != nil {
      fmt.Println("error writing to buffer")
      return
    }
    fh, err := os.Open(jsonfile)
    if err != nil {
      fmt.Println("error opening file")
      return
    }
    io.Copy(file_writer, fh)
    body_writer.Close()
    http.Post(target_url, "application/json", body_buf)
  </code></pre>