I want to POST to a URL, setting query parameters and headers and passing a raw string in the body. I then want to do the request and get the output string, so that i can convert it to JSON. I also want exception handling to respond to different kinds of errors (and handle redirects)
But Dispatch 0.9 is badly documented, breaks API with documented versions and is very quirky, so I cannot come up with a complete solution. I am utterly stuck, hence I ask for a lot.
This is all I can come up with, but setting the query params is weird:
val solr = host("localhost", 8983)
val req = solr / "update" / "json"
setQueryParameters( Map( "commit" -> "true"))
setHeader( "Content-type", "application/json")
setBody( a)
But setting the query parameters gives me a tough error:
<console>:14: error: type mismatch;
found : scala.collection.immutable.Map[java.lang.String,java.lang.String]
required: com.ning.http.client.FluentStringsMap
val req = solr / "update" / "json" setQueryParameters( Map( "commit" -> "true"))
Please help with setting the request completely: HTTPS, redirects, query parameters, headers and the POST method.
Also help with (synchronously, I want it that way) executing the request to get the body (and headers) and branching depending on the response code (200, 301, 302, 400, 500).
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…