Logstash http module not sending message - windows

I am trying to make an output POST message with the http module. I have the following config:
http {
http_method => "post"
url => "http://localhost:40104/api/message"
format => "message"
content_type => "application/json"
message => "Test"
}
It calls the API, but the POST has no body. I expect it to contain "Test".
We are using Logstash version 1.5 on Windows.
We tried using as_json after the message, we tried formatting the message as JSON, we tried sending content_type text and we tried a few other things.
Why does it not work and how can it be solved?

With this configuration I can get the message as raw body :
http {
http_method => "post"
url => "http://requestb.in/1mcpwx51"
format => "message"
content_type => "text/plain"
message => "Test"
}
I suggest you could test your output with the http://requestb.in service, it's really useful to see what input your server will get on request.
I hope that helps.

Related

HTTParty post method doesn't return status code when adding follow_redirects = false along with other headers and cookies?

The HTTParty methods are like HTTParty.XXX(urlGoesHere, and Args Here)
I'm doing the following:
params = {:UserName => "uname", :Password => "pwd"}
cookie_hash = HTTParty::CookieHash.new
cookie_hash.add_cookies("key1=val1")
cookie_hash.add_cookies("key2=val2")
options = {
:body=>params,
:headers => { 'Cookie' => cookie_hash.to_cookie_string,
'Accept' => something },
:follow_redirects => false
}
URLUserNamePwd = HTTParty.post(myURL, options) # Is this the right way to do?
When I check the http status code, body I get nothing. When I check in the browser development console, I see 302 redirect, and in response headers I see lot of header pairs returned.
What is the URL you're attempting to hit? 302 Found will be paired with a Location header containing the URL where the resource can be found.

How to Send HTTP_REQUEST without encoding?

I want to send a request without encoding the params. Because my API is expecting the params as auth_token but while sending request it got encoded to auth%5Ftoken. Because of this its throwing error. Please help me to send request without encoding. I am using gym Typhoeus to send http requests.
MY CODE:
data = {"auth_token"=>"abcd" ,"employee" => {"method" => "add_employee"}}
header = { "Content-Type" => "application/json","Accept"=>"application/json"}
request = Typhoeus::Request.post("www.example.com",:body=> data.to_json,:headers => header)

MultiJson::LoadError: 795: unexpected token when trying to parse incoming body request

I'm losing my sanity trying to parse an incoming request on a Sinatra app.
This is my spec
payload = File.read("./spec/support/fixtures/payload.json")
post "/api/v1/verify_payload", { :payload => payload }
last_response.body.must_equal payload
where is simply spec/support/fixtures/payload.json
{"ref":"refs/heads/master"}
My route looks like
post '/verify_payload' do
params = MultiJson.load(request.body.read, symbolize_keys: true)
params[:payload]
end
And running the spec I get the following error:
MultiJson::LoadError: 795: unexpected token at 'payload=%7B%22ref%22%3A%22refs%2Fheads%2Fmaster%22%7D'
I have tried to parse the body request in different ways without luck.
How can I make the request valid JSON?
THANKS
If you want to send a JSON-encoded POST body, you have to set the Content-Type header to application/json. With Rack::Test, you should be able to do this:
post "/api/v1/verify_payload", payload, 'CONTENT_TYPE' => 'application/json'
Alternatively:
header 'Content-Type' => 'application/json'
post '/api/v1/verify_payload'
More info here: http://www.sinatrarb.com/testing.html
The problem it is that you are passing a ruby hash, that is not well formated, you should pass a json object.
Something like this, should work:
post "/api/v1/verify_payload", { :payload => payload.to_json }

Unable to decode request as valid JSON using RUBY

I am making the following API GET request, using ruby 1.9.3 and the httparty gem:
uri= HTTParty.post("www.surveys.com/api/v2/contacts",
:basic_auth => auth,
:headers => { 'ContentType' => 'application/json' },
:body => {
"custom_test" => test,
"name" => firstname,
"email" => emailaddress
}
)
The variables auth,test,firstname, and emailaddress are valid. This is the response I am receiving back from my request:
{
"code": "invalid_json",
"description": "Request sent with Content-Type: application/json but was unable to decode request body as valid json.",
"success": false
}
500
#<Net::HTTPInternalServerError:0x007fe4eb98bde0>
What is wrong with the way I am posting this JSON request?
EDIT: It's probably worth noting that the API allows you to define custom attributes to a contact, hence the "custom_test" attribute in the body.
Since you are receiving an internal server error (500) instead of a not accepted (406), most likely there is coding problem on the server, because an exception that he is not expecting is happening instead of delivery to you a nice error explaining what is wrong (and this would be my first guess).
But let's say it is a problem with the JSON communication. Maybe you have to specify that you are accepting json format?
Try
:headers => { 'ContentType' => 'application/json', 'Accept' => 'application/json' },
Accept header definition from w3:
The Accept request-header field can be used to specify certain media types which are acceptable for the response. Accept headers can be used to indicate that the request is specifically limited to a small set of desired types, as in the case of a request for an in-line image.
And content-type header definition:
The Content-Type entity-header field indicates the media type of the entity-body sent to the recipient or, in the case of the HEAD method, the media type that would have been sent had the request been a GET.
You're sending a regular HTTP query string while saying it's json.
From HTTParty manual: "body: The body of the request. If it‘s a Hash, it is converted into query-string format, otherwise it is sent as-is."
Try:
:body => JSON.generate({
"custom_test" => test,
"name" => firstname,
"email" => emailaddress
})
You need to require 'JSON'

Using Bubblewrap: How to formulate get with custom headers?

I have the following Curl command that works:
curl -H "Authorization:GoogleLogin auth=xxx" http://www.google.com/reader/api/0/user-info
I'm trying to do this via a get in BubbleWrap HTTP:
HTTP.get("http://www.google.com/reader/api/0/user-info",
{
:headers => { "Authorization:GoogleLogin auth" => "xxx"}
}) do |response|
puts response
puts response.body.to_str
end
But I get a 401 back so maybe I didn't set the header correctly?
The header name is supposed to be Authorization with a value of GoogleLogin auth=xxx. The way you're doing it, it's a header name of Authorization:GoogleLogin auth with a value of xxx. Try this instead:
:headers => {"Authorization" => "GoogleLogin auth=xxx"}

Resources