如何在 Kotlin 中使用 okhttp3 进行气流实验 api?
How to use okhttp3 for airflow experimental api in Kotlin?
我需要将此命令转换为 okhttp 请求(conf
键的值必须是字符串)
curl -X POST \ http://localhost:8080/api/experimental/dags/<DAG_ID>/dag_runs \ -d '{"conf":"{\"key\":\"value\"}"}'
此代码的响应
val conf = "'{\"conf\":\"{\\"key\\":\\"$value\\"}\"}'"
val body = RequestBody.create(MediaType.parse("application/json"), conf)
val request = Request.Builder()
.url(url)
.post(body)
.header("Content-Type", "application/json")
.build()
returns
400 Bad
Request
Bad Request
The browser (or proxy) sent a
request that this server could not understand.
原因可能是格式不正确JSON。尝试使用 Kotlin 的原始字符串分配 conf
变量:
val conf = """{"conf":"{\"key\":\"$value\"}"}"""
我需要将此命令转换为 okhttp 请求(conf
键的值必须是字符串)
curl -X POST \ http://localhost:8080/api/experimental/dags/<DAG_ID>/dag_runs \ -d '{"conf":"{\"key\":\"value\"}"}'
此代码的响应
val conf = "'{\"conf\":\"{\\"key\\":\\"$value\\"}\"}'" val body = RequestBody.create(MediaType.parse("application/json"), conf) val request = Request.Builder() .url(url) .post(body) .header("Content-Type", "application/json") .build()
returns
400 BadRequest
Bad Request
The browser (or proxy) sent a request that this server could not understand.
原因可能是格式不正确JSON。尝试使用 Kotlin 的原始字符串分配 conf
变量:
val conf = """{"conf":"{\"key\":\"$value\"}"}"""