#mynavi(Go言語); #setlinebreak(on); * 目次 [#j277db0e] #contents - 関連 -- [[Go言語]] * サンプルコード [#h98a4c99] #html(<div class="pl10">) #mycode2(){{ package main import ( "bytes" "fmt" "io/ioutil" "net/http" ) const url string = "http://localhost/api/sample" func main() { client := &http.Client{} reqJson := "{\"param1\": \"abc\"}" req, _ := http.NewRequest("POST", url, bytes.NewBuffer([]byte(reqJson))) req.Header.Set("Content-Type" , "application/json") req.Header.Set("My-Header" , "Test") resp, err := client.Do(req) if err != nil { fmt.Printf("Error: %v\n", err) } defer resp.Body.Close() fmt.Printf("status : %d\n", resp.StatusCode) fmt.Printf("length : %d\n", resp.ContentLength) for k, v := range resp.Header { fmt.Printf("header %s = %v\n",k, v) } body, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Printf("error: %T\n", err) } fmt.Printf("body: %v\n", string(body)) } }} #html(</div>)