我正在嘗試通過關(guān)注https://airflow.apache.org/docs/stable/api.html這個(gè)站點(diǎn)來觸發(fā) Airflow Dags。他們提供了一個(gè) 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\"}"}'來觸發(fā) Dag。當(dāng)我從我的 Shell 執(zhí)行此命令時(shí),它正在工作。我試圖在 Go 中調(diào)用這個(gè)端點(diǎn)POST /api/experimental/dags/<DAG_ID>/dag_runs,我得到了400 Bad Request如何使用POST /api/experimental/dags/<DAG_ID>/dag_runsashttp.POST()或http.NewRequest()在 Go 中?我試過這個(gè):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貢獻(xiàn)1874條經(jīng)驗(yàn) 獲得超12個(gè)贊
我解決了。
在主要功能 -
我變了body := strings.NewReader(`{"conf":"{\"key\":\"value\"}"}`)
對(duì)此body := strings.NewReader(`{}`)
它就像一個(gè)魅力。
- 1 回答
- 0 關(guān)注
- 103 瀏覽
添加回答
舉報(bào)
0/150
提交
取消