Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8503325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:43:39+00:00 2026-06-11T01:43:39+00:00

I want to POST to a URL, setting query parameters and headers and passing

  • 0

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).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T01:43:41+00:00Added an answer on June 11, 2026 at 1:43 am

    You’re not too far off. The following should work for your request definition:

    import dispatch._
    
    val params = Map("commit" -> "true")
    val headers = Map("Content-type" -> "application/json")
    
    val solr = host("localhost", 8983)
    
    val req = solr / "update" / "json" << a <<? params <:< headers
    

    Or, less operatory-ily:

    val req = url("http://localhost:8983/update/json").POST
      .setBody(a)
      .addQueryParameter("commit", "true")
      .addHeader("Content-type", "application/json")
    

    Throw a .secure in there somewhere if you want to use HTTPS.

    You can get a promise (which essentially represents the result of a deferred request operation) like this:

    val result = Http(req OK as.String).either
    

    And then use it like this, for example:

    result() match {
      case Right(content)         => println("Content: " + content)
      case Left(StatusCode(404))  => println("Not found")
      case Left(StatusCode(code)) => println("Some other code: " + code.toString)
    }
    

    While I agree that the 0.9 documentation is sparse in some places, it does provide a very useful explanation of how to handle asynchronous request operations with promises.


    OP’s addition: this bit completes this answer for me. This gets the response in a simple, blocking way.

    val response = Http(req)()
    val body response.getResponseBody
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just want a function that can take 2 parameters: the URL to POST
So all I want to do is send a POST request to a url.
The code I want to work: $.ajax({ type: POST, url: _Source/ajap/ajap.nlSrch.php, data: { sndJson
Lets say my URL is: http://www.example.com/news/media-centre/news/17/an-example-news-post/?foo=bar I want to in PHP remove the last
I want to post in memory some child rows, and then conditionally post them,
I'm making a simple POST request via jquery's .ajax function to a routed URL
I want to do a post cross-domain request , I use a form which
I have the following headers set on the server response.addHeader(Access-Control-Allow-Origin, *); response.addHeader(Access-Control-Allow-Methods, GET, POST,
I want to post a forma poupup window. Problem is, the form posts successfully
I want to post some data to a file via ajax when somebody clicks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.