我正在尝试调用name.com API(并且成功,除了一个调用...当我尝试调用他们的Search()方法时,我收到错误。
这是我的代码:
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\n", bodyText)
return fmt.Sprintf("StatusCode: %d\n%s", resp.StatusCode, bodyText)
}
这是请求文本:
&{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>}
以下是回复:
{"message":"Invalid Argument","details":"Error occurred during parsing: Cannot decode json string."}
看来,标题中引入了一些空结构(内部,而不是我的)。或者name.com正在解析错误。
思想?