Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>While the Apache <code>HttpClient</code> would work, using it from Scala is unidiomatic and verbose, and the <a href="http://dispatch.databinder.net/Dispatch.html" rel="nofollow">Dispatch</a> library provides a nice Scala wrapper that lets you write much more concise code. You could use it like this:</p> <pre><code>import dispatch._ val u = url("https://site.com/logowanie.php") val info = Seq("username" -&gt; "me", "password" -&gt; "secret") val client = new Http client(u &lt;&lt; info &gt;&gt;&gt; System.out) </code></pre> <p>This example would simply print the response, but you can easily provide more sophisticated ways of handling the response, and your <code>client</code> now holds the cookies you need to continue interacting with the site.</p> <p>Here's a more complex example that I've used to log in to a system that required me to pick up a generated identifier from the form before logging in:</p> <pre><code>import dispatch._ import dispatch.jsoup.JSoupHttp._ val u = url("https://myuni.edu/something/login") val info = Seq( "username" -&gt; "me", "password" -&gt; "secret", "warn" -&gt; "true", "submit" -&gt; "LOGIN", "execution" -&gt; "e1s1", "_eventId" -&gt; "submit" ) val client = new Http val id = client(u &lt;/&gt; (_.select("input[name=lt]").first.attr("value"))) client(u &lt;&lt; info :+ ("lt" -&gt; id) &gt;&gt;&gt; System.out) </code></pre> <p>Here I'm using Dispatch's <a href="http://dispatch.databinder.net/JSoup.html" rel="nofollow">JSoup</a> support to parse the form page and pull out the identifier I need, which I can then add to the form parameters when I submit the request.</p>
 

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