如何使用 "application/vnd.flux" 作为内容类型在飞镖中执行 POST 请求?
How can I use "application/vnd.flux" as content-type to do a POST request in dart?
我想从 flutter 应用程序查询 influxDB,我正在使用 http 包,但我不介意更改它。这是我当前的代码(此请求在终端上运行良好):
Response response = await post(
URL,
headers: {
"Authorization": "Token $TOKEN",
"Accept": "application/csv",
"Content-type": "application/vnd.flux",
},
body: {
'data': 'from(bucket: "$BUCKET")'
'|> range(start: -48h)'
'|> filter(fn: (r) => r._measurement == "location")'
},
);
但是我得到这个错误:
[ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: Bad state: Cannot set the body fields of a Request with content-type "application/vnd.flux".
如何使用 application/vnd.flux
作为 Content-type
从这里发出 POST 请求?
我发现了错误。如果有人有同样的问题,你应该在正文中写查询raw(不带参数data
):
Response response = await post(
URL,
headers: {
"Authorization": "Token $TOKEN",
"Accept": "application/csv",
"Content-type": "application/vnd.flux",
},
body: {
'from(bucket: "$BUCKET")'
'|> range(start: -48h)'
'|> filter(fn: (r) => r._measurement == "location")'
},
);
我想从 flutter 应用程序查询 influxDB,我正在使用 http 包,但我不介意更改它。这是我当前的代码(此请求在终端上运行良好):
Response response = await post(
URL,
headers: {
"Authorization": "Token $TOKEN",
"Accept": "application/csv",
"Content-type": "application/vnd.flux",
},
body: {
'data': 'from(bucket: "$BUCKET")'
'|> range(start: -48h)'
'|> filter(fn: (r) => r._measurement == "location")'
},
);
但是我得到这个错误:
[ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: Bad state: Cannot set the body fields of a Request with content-type "application/vnd.flux".
如何使用 application/vnd.flux
作为 Content-type
从这里发出 POST 请求?
我发现了错误。如果有人有同样的问题,你应该在正文中写查询raw(不带参数data
):
Response response = await post(
URL,
headers: {
"Authorization": "Token $TOKEN",
"Accept": "application/csv",
"Content-type": "application/vnd.flux",
},
body: {
'from(bucket: "$BUCKET")'
'|> range(start: -48h)'
'|> filter(fn: (r) => r._measurement == "location")'
},
);