Note that there are some explanatory texts on larger screens.

plurals
  1. POSocketTimeoutException when I use Scalaj request
    primarykey
    data
    text
    <p>I'm trying to make a simple https request using this library <a href="https://github.com/scalaj/scalaj-http" rel="nofollow noreferrer">https://github.com/scalaj/scalaj-http</a> . The request contains some json data.</p> <p>Here is what I'm doing:</p> <pre><code> val jsonHeaders = """{"jsonrpc": "2.0", "method": "someMethod", "params": {"dataIds":["12348" , "456"]}, "data2": "777"}""" val result = Http.postData("https://someurl.com/json-rpc", jsonHeaders) .header("content-type", "application/json") .header("X-Application", "myCode") .header("X-Authentication", "myCode2") .option(HttpOptions.readTimeout(10000)) .asString //.responseCode -- the same error println(result) </code></pre> <p>And it always returns me a timeout error:</p> <pre><code>[error] (run-main) java.net.SocketTimeoutException: connect timed out java.net.SocketTimeoutException: connect timed out at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source) at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source) at java.net.AbstractPlainSocketImpl.connect(Unknown Source) at java.net.SocksSocketImpl.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at sun.security.ssl.SSLSocketImpl.connect(Unknown Source) at sun.net.NetworkClient.doConnect(Unknown Source) at sun.net.www.http.HttpClient.openServer(Unknown Source) at sun.net.www.http.HttpClient.openServer(Unknown Source) at sun.net.www.protocol.https.HttpsClient.&lt;init&gt;(Unknown Source) at sun.net.www.protocol.https.HttpsClient.New(Unknown Source) at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source) at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source) at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(Unknown Source) at scalaj.http.Http$$anonfun$3.apply(Http.scala:263) at scalaj.http.Http$$anonfun$3.apply(Http.scala:261) at scalaj.http.Http$Request.process(Http.scala:102) at scalaj.http.Http$Request.apply(Http.scala:90) at scalaj.http.Http$Request.asString(Http.scala:133) at Application$delayedInit$body.apply(Application.scala:27) at scala.Function0$class.apply$mcV$sp(Function0.scala:40) at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12) at scala.App$$anonfun$main$1.apply(App.scala:71) at scala.App$$anonfun$main$1.apply(App.scala:71) at scala.collection.immutable.List.foreach(List.scala:318) at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:32) at scala.App$class.main(App.scala:71) at Application$.main(Application.scala:8) at Application.main(Application.scala) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) [trace] Stack trace suppressed: run last compile:run for the full output. java.lang.RuntimeException: Nonzero exit code: 1 at scala.sys.package$.error(package.scala:27) </code></pre> <p>If I do just</p> <pre><code>val jsonHeaders = """{"version123": "12.0", "method": "someMethod", "params": {"dataIds": ["12348" , "456"]}, "data2": "777"}""" val result = Http.postData("https://someurl.com/some-url2", jsonHeaders) .header("content-type", "application/json") .header("X-Application", "myCode") .header("X-Application1234", "myCode2") .option(HttpOptions.readTimeout(10000)) println(result) </code></pre> <p>it returns</p> <pre><code>Request(POST,&lt;function2&gt;,&lt;function1&gt;,List(),List((X-Authentication,myCode2), (X-Application1234,myCode), (content-type,application/json)),List(&lt;function1&gt;, &lt;function1&gt;, &lt;function1&gt;),DIRECT) </code></pre> <p>What do I do wrong and is there any another simple way to send https request? Even if involves <code>spray</code> framework, it would be ok (I don't find any example of how to do that in <code>spray</code>, though).</p> <p><strong>UPDATE</strong>:</p> <p>An example has been taken from here <a href="https://stackoverflow.com/questions/11719373/doing-http-request-in-scala">Doing HTTP request in Scala</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload