-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
http_response - HTTP Request Body seems doesn't works #10839
Comments
Looking at server logs between the two requests the thing that stood out was the lack of content-type with the Telegraf response. With the curl request the content-type seen by the server appears to be:
The Telegraf request however does not set this as our "body" config option can take any random-string. I built Telegraf with a hard-coded value of: request.Header.Add("Content-Type", "application/x-www-form-urlencoded") and got the following in return:
Next steps: I think the possible options here would be to let the user set the content-type or set headers, like we do on the HTTP plugin:
|
This won't work ? |
Correct, that is not a valid URL, see https://goplay.tools/snippet/ADk_8jSijTn Edit: I should add that the code uses |
@powersj I meant setting the Content-Type header in
won't work? Referring to your comment:
Do we need to add support for headers config in http_response plugin or the existing [inputs.http_response.headers] should work ? |
I used inputs.http_response.headers like workaround but doesn't help [[inputs.http_response]]
urls = ["https://example.com/test.php"]
method = "POST"
body = '''
{'fake':'data'}
'''
response_body_field = 'test'
[inputs.http_response.headers]
Content-Type = "application/x-www-form-urlencoded" Result:
OR (with & without boundary) [[inputs.http_response]]
urls = ["https://example.com/test.php"]
method = "POST"
body = '''
{'fake':'data'}
'''
response_body_field = 'test'
[inputs.http_response.headers]
Content-Type = "multipart/form-data; boundary=----------------------------XXXXXX" Result: Can be interesting to add a parameter to be able to choose the type of data that we want to send or something like that to be flexible :) |
edit: sorry, still waking up...
Correct, that is for the response header not for sending something in a header. |
Heu it works, it's not the response header but the header set for http_response input ^^ You can try to add an Authorization and it will be sent to your backend. But concerning the Content-Type (to send POST datas), seems not really stable |
ah, we need to update the docs to make this more clear. Does this at least resolve your original issue? |
Nop :/ If I try to add the header, I have a different result but the format is really strange.
Via telegraf + header:
Concerning the doc, probably I can do a PR but concerning the code, unfortunately, it's another story :/ |
Hello, Do you have an estimation when this issue can be fixed? Best regards, |
Trying to catch back up on this, I believe this is a feature request to add the ability to post a form, something the plugin does not do currently. Right now the function takes one of the http methods to create a request and send it. To replicate what you are doing with curl, the use of the PostForm method, which uses the right header (e.g. golang post vs postform) and urlencodes the body as keys and values. No estimate, but anyone in the community free to put up a PR with a new setting to allow for this and we can review. |
With this option users can provide items to encode as a form. Combined with the POST option and header option this can be used to replicate the Post Form method. fixes: influxdata#10839
Relevant telegraf.conf
Logs from Telegraf
2022-03-17T15:46:48Z I! Starting Telegraf 1.21.4
System info
Telegraf 1.15.2 / Telegraf 1.21.4
Docker
No response
Steps to reproduce
Expected behavior
PHP is supposed to receive the data during the POST
Actual behavior
PHP didn't receive any body data during the POST
Additional info
No response
The text was updated successfully, but these errors were encountered: