Reputation: 107
I am trying to make a post request using httparty gem.
response = HTTParty.post(App.base_uri + "/api?service=post&action=update&version=2",
body: [{"some_big_json": "with many key value pair"}],
headers: {
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'Cookie' => @@cookie
})
The Body is an array. When i make a post request, I am getting this error:
/home/user/.rbenv/versions/2.5.0/lib/ruby/2.5.0/net/http/generic_request.rb:183:in send_request_with_body': undefined method bytesize' for #<Array:0x00005561f96833e0> (NoMethodError)
How to post a large array in body using httparty?
Update: In the postman i am able to send body as an array and i am getting successful(expected) response.
Upvotes: 1
Views: 1842
Reputation: 1
Just convert the array to JSON before submitting.
options = @options.merge(
body: [
{
name: 'John Doe',
}
].to_json
)
Upvotes: 0
Reputation: 595
You can also try the RestClient
RestClient::Request.execute(method: :post,
url: App.base_uri + '/api',
payload: params,
timeout: 1000,
headers: headers)
Upvotes: 0
Reputation: 595
Try to pass the string rather than array.
response = HTTParty.post(App.base_uri + "/api?service=post&action=update&version=2",
body: "[{'some_big_json': 'with many key value pair'}]",
headers: {
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'Cookie' => @@cookie
})
Upvotes: 2