Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTPS POST with Scala and Dispatch

I am trying to do a HTTPS post with scala and the Dispatch library. I can't find where to mark my connection as being https not http. Here is the code I have so far

println("Running Test")
val http = new Http
val req = :/("www.example.com" , 443) / "full/path.asp"
var response: NodeSeq = Text("")
http(req << "username=x&password=y" <> {response = _ } )
response
println("Done Running Test")

EDIT

So After attempting to figure this out I traced down what was needed the http line needs to look like this

http(req.secure << "username=x&password=y" <> {response = _ } )

Also In this specific instance I needed to POST as application/x-www-form-urlencoded that required the line to look like this

http(req.secure << ("username=x&password=y","application/x-www-form-urlencoded") <> {response = _ } )

This will now replace 40 Lines of C++ + Boost + Asio code.

like image 851
dkhenry Avatar asked Oct 10 '22 10:10

dkhenry


2 Answers

So After attempting to figure this out I traced down what was needed the http line needs to look like this

http(req.secure << "username=x&password=y" <> {response = _ } )    

Also In this specific instance I needed to POST as application/x-www-form-urlencoded that required the line to look like this

http(req.secure << ("username=x&password=y","application/x-www-form-urlencoded") <> {response = _ } 
like image 143
dkhenry Avatar answered Oct 14 '22 01:10

dkhenry


You could apply "secure" to the :/ factory:

:/("host").secure
like image 35
Brett Avatar answered Oct 14 '22 03:10

Brett