Reeebuuk
Reeebuuk

Reputation: 1381

Akka-http https call returning 403

I'm trying to make this call

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  ]}'

and is working normally locally via postman or curl but using akka-http I cannot get through.

Have tried to manually accept every SSL hostname verification but that doesn't help as well. Always getting 403 Forbidden.

When I tried some other tricks I eventually get SSLEngine problem which again leads me nowhere.

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)
    )

I'm using the akka-http 10.1.0.

Upvotes: 0

Views: 519

Answers (1)

James
James

Reputation: 2764

Turns out you need to pass the correct Content-Type header and data. I guess it's specific to how it's implemented in that server. So, the below code works:

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`
    )
)

Upvotes: 3

Related Questions