How to send data in a post request with RestClient

rboling

I'm trying to mimic a curl request using the RestClient Ruby gem, and so far, I've been having a lot of trouble trying to send in a payload. My curl request looks something like this

curl URL -X POST -u API_KEY -d '{"param_1": "1"}'

I've been trying to replicate this with RestClient using something like this:

RestClient::Request.execute(method: :post, url: URL, user: API_KEY, payload: {"param_1" => "1"})

Alas, I keep getting 400 - Bad Requests errors when doing this. Am I sending data over the wrong way? Should I be using something other than payload?

K M Rakibul Islam

Change:

payload: {"param_1" => "1"})

To:

payload: '{"param_1": "1"})'

Also, specify the headers.

So, it becomes:

RestClient::Request.execute(method: :post,
                            url: 'your_url',
                            user: 'API_KEY',
                            payload: '{"param_1": "1"}',
                            headers: {"Content-Type" => "application/json"}
                           )

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Delphi RESTClient POST request

From Dev

Pass parameters in RestClient post request

From Dev

Pass parameters in RestClient post request

From Dev

How to send json data in the Http request to POST Method in JSON Parsing

From Dev

How to send POST request using HTTPURLConnection with JSON data

From Dev

How to send a cURL POST without request data in PHP?

From Dev

How to send state data via POST request in Vuex?

From Dev

How I can send POST request with data from table?

From Dev

How to send form data in post request in iOS using MonoTouch?

From Dev

How to send a post request with data using python requests module?

From Dev

How to send json data in the Http request to POST Method in JSON Parsing

From Java

How to send a POST request in Go?

From Dev

How to send a post request to GTMetrix

From Dev

How to send a post request to GTMetrix

From Dev

What is the difference between RestClient::Request.execute and RestClient.post?

From Dev

How to send request to a website through POST request?

From Java

Send POST request with JSON data using Volley

From Java

axios post request to send form data

From Dev

Send Default data through ajax post request

From Dev

Send post request data on codeigniter with special values

From Dev

Send data using POST to JSONP request

From Dev

Send POST request over Mobile Data

From Dev

Send post request data on codeigniter with special values

From Dev

Difference of send POST request with json data or parameter?

From Dev

JMeter get jdbc request data and send each with http post request in a spring service how-to

From Dev

How to send data from django template to views method in post request or in a way data is not visible in the URL

From Dev

How to send a POST request in Swift with a variable

From Dev

How to send HTTP POST request in Xamarin?

From Dev

How to send HTTP POST request with AFNetworking?

Related Related

  1. 1

    Delphi RESTClient POST request

  2. 2

    Pass parameters in RestClient post request

  3. 3

    Pass parameters in RestClient post request

  4. 4

    How to send json data in the Http request to POST Method in JSON Parsing

  5. 5

    How to send POST request using HTTPURLConnection with JSON data

  6. 6

    How to send a cURL POST without request data in PHP?

  7. 7

    How to send state data via POST request in Vuex?

  8. 8

    How I can send POST request with data from table?

  9. 9

    How to send form data in post request in iOS using MonoTouch?

  10. 10

    How to send a post request with data using python requests module?

  11. 11

    How to send json data in the Http request to POST Method in JSON Parsing

  12. 12

    How to send a POST request in Go?

  13. 13

    How to send a post request to GTMetrix

  14. 14

    How to send a post request to GTMetrix

  15. 15

    What is the difference between RestClient::Request.execute and RestClient.post?

  16. 16

    How to send request to a website through POST request?

  17. 17

    Send POST request with JSON data using Volley

  18. 18

    axios post request to send form data

  19. 19

    Send Default data through ajax post request

  20. 20

    Send post request data on codeigniter with special values

  21. 21

    Send data using POST to JSONP request

  22. 22

    Send POST request over Mobile Data

  23. 23

    Send post request data on codeigniter with special values

  24. 24

    Difference of send POST request with json data or parameter?

  25. 25

    JMeter get jdbc request data and send each with http post request in a spring service how-to

  26. 26

    How to send data from django template to views method in post request or in a way data is not visible in the URL

  27. 27

    How to send a POST request in Swift with a variable

  28. 28

    How to send HTTP POST request in Xamarin?

  29. 29

    How to send HTTP POST request with AFNetworking?

HotTag

Archive