使用golang的http请求中的nil chan,中断通话

I am attempting to call the name.com API (and am successful, except for one call... When I attempt to call their Search() method, I am getting an error.

Here is my code:

func TestExecute() string{
    client := &http.Client{}
    body := []byte("keyword=web")
    req, newReqErr := http.NewRequest("POST", "https://api.name.com/v4/domains:search", bytes.NewBuffer(body))
    check("new Request Error: ", newReqErr)

    req.SetBasicAuth("username", "[TOKEN ]")

    fmt.Println(req)

    resp, doErr := client.Do(req)
    check("client Do Error: ", doErr)

    bodyText, readErr := ioutil.ReadAll(resp.Body)
    check("Read error: ", readErr)

    fmt.Printf("Result: %s
", bodyText)

    return fmt.Sprintf("StatusCode: %d
%s", resp.StatusCode, bodyText)

}

Here is the request text:

&{POST https://api.name.com/v4/domains:search HTTP/1.1 1 1 map[Authorization:[Basic cldokleodjjAzMWNlODY2MjRlYmI5xxkxjdkfOWI4ZjNhMWQ5NmVmOGIA5YTA=]] {keyword=web} 11 [] false api.name.com map[] map[] <nil> map[]   <nil> <nil>}

and here is the response:

{"message":"Invalid Argument","details":"Error occurred during parsing: Cannot decode json string."}

It appears that some empty structs (internals, not mine) are being introduced into the header. OR name.com is parsing incorrectly.

Thoughts?

According to Name.com API Documentation the body of a POST /v4/domains:search request needs to be represented as JSON. They show an example JSON body in the sidebar.

{"keyword":"example"}

To produce the JSON body and be sure that all escaping has happened correctly, let's define the following JSON formattable struct.

type DomainSearch struct {
    Keyword string `json:"keyword"`
}

Then replace your body := []byte("keyword=web") with a JSON body:

body, err := json.Marshal(DomainSearch{"web"})

Assuming you have a valid Name.com API token you should see a 200 response come back with a JSON response body, something like:

{
  "results": [
    {
      "domainName": "web.blog",
      "sld": "web",
      "tld": "blog"
    },
    {
      "domainName": "web.cam",
      "sld": "web",
      "tld": "cam"
    },
    {
      "domainName": "web.camera",
      "sld": "web",
      "tld": "camera",
      "purchasable": true,
      "premium": true,
      "purchasePrice": 500,
      "purchaseType": "registration",
      "renewalPrice": 500
    },
    {
      "domainName": "web.cloud",
      "sld": "web",
      "tld": "cloud"
    },
    ...
  ]
}