Disable SSL using Scala Dispatcher Library

Currently, I am moving all Rest tests to the CI server and noticed that all tests do not work due to SSL handshaking, now I have successfully disabled this using TrustManager using our Java test suite, but I'm not sure how to do this with Scala's mailing list library, and havent been able to find many examples that could be used in this scenario.

val JSONstr = "{samplekey:samplevalue}" val response:String = Http(url("https://www.host.com/path/to/post") << (checkInJSONstr, "application/json") as_str) 

The following exception occurs as expected:

 javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated at com.sun.net.ssl.internal.ssl.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:352) ... 

Is there a way to do this purely syntactically ignoring SSL with the send library?

+4
source share
2 answers
 import dispatch._ val http = new Http with HttpsLeniency val response:String = http(url("https://www.host.com/path/to/post") << (checkInJSONstr, "application/json") as_str) 
+6
source

Answer viktortnk no longer works with the latest version of Dispatch (0.13.2). For the latest version, you can use the following to create an http client that accepts any certificate:

 val myHttp = Http.withConfiguration(config => config.setAcceptAnyCertificate(true)) 

Then you can use it for GET requests as follows:

 myHttp(url("https://www.host.com/path").GET OK as.String) 

I found this here: Why is the sending throw a "java.net.ConnectException: General SSLEngine ..." and an "unexpected status" exception for a specific URL?

0
source

Source: https://habr.com/ru/post/1436193/


All Articles