我正在尝试通过关注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 关注
- 134 浏览
添加回答
举报
0/150
提交
取消
