当尝试使用akka-http对某些内部端点执行简单的POST请求时,出现问题。当执行这段代码:Akka-http POST结果为“服务器端HTTP版本不受支持”
for {
request <- Marshal(merchantTransactionRequest).to[RequestEntity]
response <- Http().singleRequest(
HttpRequest(
method = HttpMethods.POST,
uri = "http://foo/bar:8080",
entity = request.withContentType(ContentTypes.`application/json`)
)
)
...
} yield ...
我得到迎接以下错误:
akka.http.scaladsl.model.IllegalResponseException: The server-side HTTP version is not supported at akka.http.impl.engine.client.OutgoingConnectionBlueprint$PrepareResponse$$anon$1.onPush(OutgoingConnectionBlueprint.scala:191) ...
即将由以下日志之前:
[0] </10.0.0.135:42610->foo:8080> pushing request to connection: POST bar Strict(508 bytes)
由于部分我调试过程中,我使用curl对端点执行了相同的查询,该curl成功(并且响应了HTTP/1.1
)。由于HttpRequest(...)
默认使用protocol = HttpProtocols.`HTTP/1.1`
,所以我怀疑akka-http和这个其他端点之间协商的HTTP版本不正确。
当akka-http做POST时,有可能以某种方式强制执行HTTP版本吗?或者为什么curl成功完成POST,而akka-http没有任何其他线索?请注意,问题只发生在POST的时候,而不是GET的。
我有同样的问题,你能详细说明一下吗?在你的回答中,你对两者都使用“直接连接”这个短语。我知道'localhost'起作用,没有TLD。你如何解释? –