我正在嘗試訪問這樣的 API:package mainimport ( "bytes" "fmt" "io/ioutil" "net/http" "net/url")func main() { apiUrl := "https://example.com/api/" data := url.Values{} data.Set("api_token", "MY_KEY") data.Add("action", "list_projects") req, _ := http.NewRequest("POST", apiUrl, bytes.NewBufferString(data.Encode())) client := &http.Client{} resp, err := client.Do(req) defer resp.Body.Close() if err == nil { body, _ := ioutil.ReadAll(resp.Body) fmt.Println(resp.Status) fmt.Println(string(body)) }}但是來自 API 的響應(yīng)告訴我 POST 請求中沒有數(shù)據(jù)。如果我用 curl 這樣做,它會起作用:$ curl -X POST "https://example.com/api/" -d "api_token=MY_KEY" -d "action=list_projects"
- 1 回答
- 0 關(guān)注
- 148 瀏覽
添加回答
舉報
0/150
提交
取消