我需要使用 Spray 发出发布请求,但我不明白如何在服务器端捕获请求。这是我的代码:
客户:
.
.
val pipeline: HttpRequest => Future[HttpResponse] = sendReceive
val fileName = "document.docx"
val path = getClass.getResourceAsStream("/test-documents/" + fileName)
val bytes = IOUtils.toByteArray(path)
val bytes64 = Base64.encodeBase64(bytes)
val streamInString = new String(bytes64)
val json: JsonInputStream = JsonInputStream(fileName, streamInString)
val jsonString = write(json)
val response: Future[HttpResponse] = pipeline(Post("http://localhost:8080/jsontest/", jsonString))
SERVER(4 个测试中的任何一个都没有捕获到请求):
startServer(interface = "localhost", port = 8080) {
path("jsontest") {
post {
complete {
<h1>TEST 1</h1>
}
}
} ~
path("jsontest" / Segment) { json =>
post {
complete {
<h1>TEST 2</h1>
}
}
} ~
path("jsontest") {
get {
complete {
<h1>TEST 3</h1>
}
}
} ~
path("jsontest" / Segment) { json =>
get {
complete {
<h1>TEST 4</h1>
}
}
}
}
请帮帮我