Sending a custom POST https request in dispatch (+cookies, + headers)

アレックス

There is some documentation about sending post request in dispatch http://dispatch.databinder.net/Combined+Pages.html but yet it's not clear. What are myRequest and myPost there?

I want to send a https post request + add some cookies manually via headers + add some customs headers like form data, etc, and then read the response by reading the headers and cookies.

I only know how to prepare url for sending post request:

val url = host(myUrl + "?check=1&val1=123").secure

What do I do next?

user24601

Dispatch is built on top of Async Http Client. Therefore, myRequest in the example:

 val myRequest = url("http://example.com/some/path")

is com.ning.http.client.RequestBuilder.

Calling the POST method on RequestBuilder turns the request into a POST request. That's what's happening in the myPost example:

def myPost = myRequest.POST

I often find the Dispatch documentation difficult to follow. For a quick overview of the all the various Dispatch operators, see: Periodic Table of Dispatch Operators

If you're asking how to build a POST request and add custom form parameters, you probably want to use the <<(values) operator like this:

val params = Map("param1" -> "val1", "param2" -> "val2") 
val req = url("http://www.example.com/some/path" <<(params)

Likewise if you want to add some custom headers you can use the <:<(map) operator like this:

val headers = Map("x-custom1" -> "val1", "x-custom2" -> "val2") 
val req = url("http://www.example.com/some/path" <<(params) <:<(headers)

Update: Actually, there is no POST method on RequestBuilder. The call to POST is part of Dispatch and calls setMethod on the underlying RequestBuilder. See dispatch.MethodVerbs for more details.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Python, sending a request with headers and cookies

Sending POST request with HTTP headers

Sending HTTPS POST request with ABAP

Why isn't the post request sending cookies?

issue with sending headers in post request to the API

Sending POST request from Unity WebGL to HTTPS

SSLHandshakeException when sending POST request via https

Sending HTTPS Post Request in Android/Java

How to use Alamofire with custom headers for POST request

Flask and Werkzeug: Testing a post request with custom headers

POST with custom headers using Request Library

Send POST request with custom headers using flash

Sending payload in POST request in Vegeta with custom attacker

What is the correct format for sending cookies in a post request with Python Requests?

HttpWebRequest not sending cookies on POST

How to display body and headers before sending POST request?

Axios not sending headers, post request failing, getting 401

Sending request headers / authorization axios.post in react-native

Axios not sending custom headers in request (possible CORS issue)

Chrome app jquery AJAX request not sending custom headers

Spring RestTemplate to POST request with Custom Headers and a Request Object

Sending password over XML HTTP request post (HTTPS enabled)

Sending POST requests using Cookies

Sending form data to a custom post type WP with AJAX request

Sending custom headers through RSpec

Sending custom HTTP headers with Ruby

Cordova FileTransfer not sending custom headers

Alamofire POST request with headers

POST Request Not Recognizing Headers