我正在使用http Akka编写一个应用程序,我想发布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);
}
createRoute函数:
public Route createRoute() {
return route(
post(() -> route(
panelDataUpload()
)),
get(() -> route(
path("health-check", this::healthCheck)
))
);
}
panelDataUpload函数:
private Route panelDataUpload() {
return path(PathMatchers
.segment("panel")
.slash("data"), () -> parameterList
(parameters -> entity(entityToString(), this::processRequestData))
);
}
当我在processRequestData中显示String时,得到的单行字符串不带“ / 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
有什么方法可以从实体获取行尾标记吗?我在做什么错了?
答案 0 :(得分:0)
问题出在curl上,-d标志跳过换行符,--data-binary标志使其完美运行。谢谢