Answer the question
In order to leave comments, you need to log in
How to insert header in post request?
I'm trying to figure out the Avito API.
https://autoload.avito.ru/format/api/#section/Obsh...
Here you need to somehow insert the token into the header. Google-google can not figure out how to do it.
I get the token without problems:
require "net/http"
require "uri"
require 'json'
uri_token = URI.parse("https://api.avito.ru/token/")
response_token = Net::HTTP.post_form(uri_token, {"grant_type" => "client_credentials", "client_id" => "client_id", "client_secret" => "client_secret"})
result=JSON.parse(response_token.body)
token=result['access_token']
Answer the question
In order to leave comments, you need to log in
In short, I found the solution myself. If someone needs it, then here:
uri = URI(" https://api.avito.ru/autoload/v1/accounts/{id_user... ")
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
req = Net::HTTP::Get.new(uri)
req['Authorization'] = 'Bearer '+token
concat http.request(req).body
end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question