Is this the correct way of doing a post in HTTPoison?

Background

I have a POST request that I do using CURL the following way:

curl --data “reqCode=validateOfficeDetails&currLanguage=ca_ES” -X POST https://ovt.gencat.cat/gsitfc/AppJava/citpre/citpre.do

My objective is to replicate this request using HTTPoison.

Code

Thus far, this is how I am doing it:

HTTPoison.post("https://ovt.gencat.cat/gsitfc/AppJava/citpre/citpre.do", "reqCode=validateOfficeDetails&currLanguage=ca_ES", [{"Content-Type", "application/x-www-form-urlencoded"}])

But I am unsure this is the way to go because I am placing the --data parameters in what is the body.
Is this correct?

I would say yes? Is it not working?

2 Likes

POST data is sent in the request body, so I’d say yes :slight_smile:

You are correctly setting the Content-Type to form urlencoded, matching your data.

We are so used to HTTP abstractions that it’s easy to forget how HTTP is really just text: request method, headers and body, it’s that simple :wink:

3 Likes