Akka-http https调用返回403
Akka-http https call returning 403
我正在尝试拨打这个电话
curl -X POST \
'https://structuredproducts-ch.leonteq.com/engine-
api/feed/timeseries/request?from=201805310000&to=201805311602' \
-H 'accept: application/json' \
-H 'content-type: application/json' \
-d '{ "sophisInternalIds": [ 67108959 ]}'
并且通过 postman 或 curl 在本地正常工作,但使用 akka-http 我无法通过。
已尝试手动接受每个 SSL 主机名验证,但这也无济于事。总是得到 403 Forbidden。
当我尝试其他一些技巧时,我最终遇到了 SSLEngine 问题,这又导致我无处可去。
private val trustfulSslContext: SSLContext = {
object NoCheckX509TrustManager extends X509TrustManager {
override def checkClientTrusted(chain: Array[X509Certificate], authType: String): Unit = ()
override def checkServerTrusted(chain: Array[X509Certificate], authType: String): Unit = ()
override def getAcceptedIssuers: Array[X509Certificate] = Array[X509Certificate]()
}
val context = SSLContext.getInstance("TLS")
context.init(Array[KeyManager](), Array(NoCheckX509TrustManager), null)
context
}
Http(context.system)
.singleRequest(
HttpRequest(
uri = Uri(url),
method = HttpMethods.POST,
entity = "lala",
protocol = HttpProtocols.`HTTP/1.1`),
connectionContext = ConnectionContext.https(trustfulSslContext)
)
我正在使用 akka-http 10.1.0。
原来你需要传递正确的 Content-Type
header 和数据。我想这与它在该服务器中的实现方式有关。所以,下面的代码有效:
val requestEntity: RequestEntity = HttpEntity.Strict(
contentType = ContentTypes.`application/json`,
data = ByteString("{ \"sophisInternalIds\": [ 67108959 ]}")
)
Http(context.system)
.singleRequest(
HttpRequest(
uri = Uri("https://structuredproducts-ch.leonteq.com/engine-api/feed/timeseries/request?from=201805310000&to=201805311602"),
method = HttpMethods.POST,
entity = requestEntity,
protocol = HttpProtocols.`HTTP/1.1`
)
)
我正在尝试拨打这个电话
curl -X POST \
'https://structuredproducts-ch.leonteq.com/engine-
api/feed/timeseries/request?from=201805310000&to=201805311602' \
-H 'accept: application/json' \
-H 'content-type: application/json' \
-d '{ "sophisInternalIds": [ 67108959 ]}'
并且通过 postman 或 curl 在本地正常工作,但使用 akka-http 我无法通过。
已尝试手动接受每个 SSL 主机名验证,但这也无济于事。总是得到 403 Forbidden。
当我尝试其他一些技巧时,我最终遇到了 SSLEngine 问题,这又导致我无处可去。
private val trustfulSslContext: SSLContext = {
object NoCheckX509TrustManager extends X509TrustManager {
override def checkClientTrusted(chain: Array[X509Certificate], authType: String): Unit = ()
override def checkServerTrusted(chain: Array[X509Certificate], authType: String): Unit = ()
override def getAcceptedIssuers: Array[X509Certificate] = Array[X509Certificate]()
}
val context = SSLContext.getInstance("TLS")
context.init(Array[KeyManager](), Array(NoCheckX509TrustManager), null)
context
}
Http(context.system)
.singleRequest(
HttpRequest(
uri = Uri(url),
method = HttpMethods.POST,
entity = "lala",
protocol = HttpProtocols.`HTTP/1.1`),
connectionContext = ConnectionContext.https(trustfulSslContext)
)
我正在使用 akka-http 10.1.0。
原来你需要传递正确的 Content-Type
header 和数据。我想这与它在该服务器中的实现方式有关。所以,下面的代码有效:
val requestEntity: RequestEntity = HttpEntity.Strict(
contentType = ContentTypes.`application/json`,
data = ByteString("{ \"sophisInternalIds\": [ 67108959 ]}")
)
Http(context.system)
.singleRequest(
HttpRequest(
uri = Uri("https://structuredproducts-ch.leonteq.com/engine-api/feed/timeseries/request?from=201805310000&to=201805311602"),
method = HttpMethods.POST,
entity = requestEntity,
protocol = HttpProtocols.`HTTP/1.1`
)
)