title: Why Golang treats my POST request as a GET one?
body: <p>My server code like:</p>
  
  <pre><code>// golang
  type SomeHandler struct{}
  
  func (*SomeHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
      fmt.Println("method:", req.Method)
      fmt.Println("content length:", req.ContentLength)
  
      // read request body as []byte
      content, err := ioutil.ReadAll(req.Body)
      if err != nil {
          // do sth.
          return
      }
  
      // decode JSON
      // ...
  }
  </code></pre>
  
  <p>Client side:</p>
  
  <pre><code>// Objective-C on iOS 6/7
  // NSURL *myUrl = ...
  NSMutableURLRequest *req = [[NSMutableURLRequest alloc] initWithURL:myUrl];
  [req setHTTPMethod:@"POST"];
  [req setValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
  
  id obj = @{
               @"username" : @"myname",
               @"password" : @"mypwd",
            };
  NSError *error;
  NSData *inputJson = [NSJSONSerialization dataWithJSONObject:obj options:0 error:&amp;error];
  if (error) {
      // no error here
  }
  [req setHTTPBody:inputJson];
  
  [NSURLConnection sendAsynchronousRequest:req queue:[NSOperationQueue mainQueue]
                         completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
  
      if (error) {
          NSLog(@"ERROR: %@", error.localizedDescription);
          return;
      }
  
      NSHTTPURLResponse *resp = (NSHTTPURLResponse *)response;
      NSString *outputText = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
      NSLog(@"response (%d):\n%@", (int)resp.statusCode, outputText);
  }
  </code></pre>
  
  <p>When I run this iOS code in iPhone simulator the server side shows:</p>
  
  <pre><code>method: GET
  content length: 0
  </code></pre>
  
  <p>Chage my client side code: <code>[req setHTTPMethod:@"HEAD"];</code>, the server works:</p>
  
  <pre><code>method: HEAD
  content length: &lt;some length&gt;
  </code></pre>
  
  <p>I don't know what's wrong with my POST code on the client or what should I do on the server to retrieve data as []byte my client just sent.</p>
  
  <p>btw,
  my go version:</p>
  
  <pre><code>$ go version
  go version go1.2.1 darwin/amd64
  </code></pre>