我正在嘗試通過關注https://airflow.apache.org/docs/stable/api.html這個站點來觸發 Airflow Dags。他們提供了一個 curl 命令curl -X POST \ http://localhost:8080/api/experimental/dags/<DAG_ID>/dag_runs \ -H 'Cache-Control: no-cache' \ -H 'Content-Type: application/json' \ -d '{"conf":"{\"key\":\"value\"}"}'來觸發 Dag。當我從我的 Shell 執行此命令時,它正在工作。我試圖在 Go 中調用這個端點POST /api/experimental/dags/<DAG_ID>/dag_runs,我得到了400 Bad Request如何使用POST /api/experimental/dags/<DAG_ID>/dag_runsashttp.POST()或http.NewRequest()在 Go 中?我試過這個:package mainimport ( "encoding/json" "fmt" "net/http" "strings")func main(){ body := strings.NewReader(`{"conf":"{\"key\":\"value\"}"}`) req, err := http.NewRequest("POST", "http://localhost:8080/api/experimental/dags/airflow_sample/dag_runs", body) if err != nil { fmt.Println(err) } req.Header.Set("Cache-Control", "no-cache") req.Header.Set("Content-Type", "application/json") resp, err := http.DefaultClient.Do(req) if err != nil { fmt.Println(err) } fmt.Println(resp) defer resp.Body.Close()}
1 回答

HUWWW
TA貢獻1874條經驗 獲得超12個贊
我解決了。
在主要功能 -
我變了body := strings.NewReader(`{"conf":"{\"key\":\"value\"}"}`)
對此body := strings.NewReader(`{}`)
它就像一個魅力。
- 1 回答
- 0 關注
- 104 瀏覽
添加回答
舉報
0/150
提交
取消