A
A
Andrey2018-05-04 16:20:11
Ruby on Rails
Andrey, 2018-05-04 16:20:11

How to send json object to someone else's api?

I have a js request like this:

url : 'example.com/json.php',
jsonp : 'callback',
data : {"json" : DataJson},
type : 'GET',
dataType : "jsonp",

You need to rewrite it on the server:
DataJson = "{'senderCityId':'506','receiverCityId':'320'}"
uri = URI("example.com/json.php")
params = {"json" => DataJson}
uri.query = URI.encode_www_form(params)
res = Net::HTTP.get_response(uri)
h = JSON.parse(res.body)

The service returns an error that json is expected.
It turns out that the server is sent
http://example.com/json.php?json={'senderCityId':'506','receiverCityId':'320'}

In what form is the json object generally sent?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Shakhunov, 2018-05-06
@inf

Somehow so . It is necessary to add data to the body of the request, and not to the query.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question