我正在用 http Akka 编写一个应用程序,我想 POST json 文件,里面有 csv 并解析它。当我使用 enitityToString() 时,我得到单行字符串而不是带有 /n 的字符串。
我的http服务器:
public static void createHttpServer(ApplicationRouter applicationRouter) {
ActorSystem actorSystem = ApplicationProperties.actorSystem;
Http http = Http.get(actorSystem);
ActorMaterializer actorMaterializer = ActorMaterializer.create(actorSystem);
Flow<HttpRequest, HttpResponse, NotUsed> routeFlow = applicationRouter
.createRoute()
.flow(actorSystem, actorMaterializer);
http.bindAndHandle(routeFlow, ConnectHttp.toHost(ApplicationProperties.httpHost,
Integer.parseInt(ApplicationProperties.httpPort)), actorMaterializer);
}
创建路由函数:
public Route createRoute() {
return route(
post(() -> route(
panelDataUpload()
)),
get(() -> route(
path("health-check", this::healthCheck)
))
);
}
面板数据上传功能:
private Route panelDataUpload() {
return path(PathMatchers
.segment("panel")
.slash("data"), () -> parameterList
(parameters -> entity(entityToString(), this::processRequestData))
);
}
当我在 processRequestData 中显示字符串时,我得到没有“/n”之类的单行字符串。
我要发送的文件:
{
"table": "panelTest",
"panel-data": "header1,header2,header3
va0,va1,va2
v10,v11,v12
v20,v21,v22"
}
卷曲:
curl -d @"import.txt" -H "Content-Type: application/json" -X POST http://localhost:8777/panel/data
有没有办法从实体中获取行尾标记?我究竟做错了什么?
catspeake
相关分类