title: Golang HTTP Post error: connection refused
body: <p>I am trying to send a post request to localhost on port 8080 where a PHP app is running.</p>
  
  <p>Curl work fine:</p>
  
  <pre><code>curl --data "key=asdf" http://localhost:8080/
  </code></pre>
  
  <p>But in Go I get the following error:</p>
  
  <pre><code>Post http://localhost:8080: dial tcp 127.0.0.1:8080: connection refused
  </code></pre>
  
  <p>Here is the code:</p>
  
  <pre><code>func submitForm(value string){
      resp, err := http.PostForm("http://localhost:8080", url.Values{"key": {value}})
      if err != nil {
          log.Fatal(err)
      }
      defer resp.Body.Close()
      _, err = ioutil.ReadAll(resp.Body)
      if err != nil {
          log.Fatal(err)
      }
      fmt.Println("status = ",resp.Status)
  }
  submitForm("asdf")
  </code></pre>
  
  <p>I monitored http traffic with httpry and i found out that no http request is generated but there are some packages:</p>
  
  <pre><code>4 packets received, 0 packets dropped, 0 http packets parsed
  </code></pre>
  
  <p>Some more facts:</p>
  
  <ul>
  <li>My OS is Linux</li>
  <li><p>I use the PHP's built-in web server. The servers was started with this command:</p>
  
  <p>php -S localhost:8080</p></li>
  </ul>