I have curl str
curl -L –user '61332:Ne5re3w34fa' -H «Content-Type: application/json» -d '{«confirmed_at»: {«date»:«2014-04-30», «period»: 30}, «merchant_id»:73, «state»:[3,4], «type»: 0, «sub_id»:«test»}' -X POST https://myurl/
which returns me data in console
But how to use it inside rails app?
Ruby stdlib has opportunity to run system commands
Here is good review of all possible variants: Calling shell commands from Ruby
Also there is curl gem: https://rubygems.org/gems/curb
Related
I am new on Icinga2, using 2.4.0 version and I am trying to execute some API calls but I have found a problem when I have tried to create a service manually.
This is the command that I execute to create a service called api_dummy_service_1 for api_dummy_host_1 host:
curl -u $ICINGA2_API_USER:$ICINGA2_API_PASSWORD \
-H 'Accept: application/json' -X PUT \
-k "https://$ICINGA2_HOST:$ICINGA2_API_PORT/v1/objects/services/api_dummy_host_1!api_dummy_service_1" \
-d '{ "templates": [ "generic-service" ], "attrs": { "display_name": "api_dummy_service_1", "check_command" : "dns", "vars.dns_lookup": "google-public-dns-a.google.com.", "vars.dns_expected_answer": "8.8.8.8", "host_name": "api_dummy_host_1" } }' | python -m json.tool
When I execute it, the following error message appears:
-bash: !api_dummy_service_1: event not found
I have examinated Icinga logs, I have activated debug mode on Icinga also and tried to search information related to this in internet with no results.
Can anyone help me please? Thanks in advance!
Issue fixed! After doing more test in detail we have detected that the problem was related to the URL that we use to connect with icinga2 API, the ! character must be escaped.
I have changed ! to %21 and the command works
We have an application that we would like to run a script on just like we do in the console window with access to the applications libraries and context, but we need to run it periodically like a cron job.
While the permanent answer is obviously a Quartz job, we need to the do this before we are able to patch the application.
Is there something available that gives us the same environment as the console-plugin but can be run via command-line or without a UI?
you can run a console script like the web interface does but just with a curl like this:
curl -F 'code=
class A {
def name
}
def foo = new A(name: "bar")
println foo.name
' localhost:8080/console/execute
You'll get the response as the console would print below.
With regard to #mwaisgold 's solution above, I made a couple of quick additions that helped. I added a little bit more to the script to handle authentication, plus the -F flag for curl caused an ambiguous method overloading error with the GroovyShell's evaluate method, so I addressed that by using the -d instead:
#/bin/bash
curl -i -H "Content-type: application/x-www-form-urlencoded" -c cookies.txt -X POST localhost:8080/myapp/j_spring_security_check -d "j_username=admin&j_password=admin"
curl -i -b cookies.txt -d 'code=
int iterations = 0
while (iterations < 10) {
log.error "********** Console Cron Test ${iterations++} ***********"
}
log.error "********** Console Cron Test Complete ***********"
' localhost:8080/myapp/console/execute
I want to upload a file together with some information(e.g. package_type) with curl
in my submission model:
has_attached_file :package
What I tried:
curl -d "submission[package_type]=type1&submission[package]=#/home/ubuntu/Downloads/test.zip" http://localhost:3000/restapi.json
If I leave out the file object, it works(a entry will be inserted into the database)
But I specify the file like above, it gives me an error:
No handler found for "#/home/ubuntu/Downloads/test.zip"
Update:
I just found that that I should use the -F option in curl, but in that case the file information cannot be recorded, is there anyway to include both the file object and file info? Maybe something like curl -d -F ?
I had a similar issue and ended up setting the content-type to multipart/form-data instead of dealing with base64 encoding issues when posting to my REST API. Here is an example which includes headers for auth:
curl -v -H 'Content-Type: multipart/form-data' -H "X-User-Email: <email>" -H "X-User-Token: <token>" -X POST -i -F submission[package_type]=type1 -F submission[image_attributes][image]=#f117.jpg http://localhost:3000/api/v1/submissions
I am using cURL command line utility to send HTTP POST to a web service. I want to include a file's contents as the body entity of the POST. I have tried using -d </path/to/filename> as well as other variants with type info like --data </path/to/filename> --data-urlencode </path/to/filename> etc... the file is always attached. I need it as the body entity.
I believe you're looking for the #filename syntax, e.g.:
strip new lines
curl --data "#/path/to/filename" http://...
keep new lines
curl --data-binary "#/path/to/filename" http://...
curl will strip all newlines from the file. If you want to send the file with newlines intact, use --data-binary in place of --data
I know the question has been answered, but in my case I was trying to send the content of a text file to the Slack Webhook api and for some reason the above answer did not work. Anywho, this is what finally did the trick for me:
curl -X POST -H --silent --data-urlencode "payload={\"text\": \"$(cat file.txt | sed "s/\"/'/g")\"}" https://hooks.slack.com/services/XXX
In my case, # caused some sort of encoding problem, I still prefer my old way:
curl -d "$(cat /path/to/file)" https://example.com
curl https://upload.box.com/api/2.0/files/3300/content -H "Authorization: Bearer $access_token" -F file=#"C:\Crystal Reports\Crystal Reports\mysales.pdf"
How do I include special characters like # and & in the cURL POST data? I'm trying to pass a name and password like:
curl -d name=john passwd=#31&3*J https://www.mysite.com
This would cause problems as # is used for loading files and & for specifying more than one key/value. Is there some way I can escape these characters? \# and \& don't seem to work.
cURL > 7.18.0 has an option --data-urlencode which solves this problem. Using this, I can simply send a POST request as
curl -d name=john --data-urlencode passwd=#31&3*J https://www.example.com
Summarizing the comments, in case of mixed "good" and "bad" data and exclamation marks inside we can use on Windows:
curl -d "grant_type=client_credentials&client_id=super-client&acr_values=tenant:TNT123" --data-urlencode "client_secret=XxYyZ21D8E&%fhB6kq^mXQDovSZ%Q*!ipINme" https://login.example.com/connect/token
How about using the entity codes...
# = %40
& = %26
So, you would have:
curl -d 'name=john&passwd=%4031%263*J' https://www.mysite.com
Double quote (" ") the entire URL .It works.
curl "http://www.mysite.com?name=john&passwd=#31&3*J"
Just found another solutions worked for me. You can use '\' sign before your one special.
passwd=\#31\&3*J
Try this:
export CURLNAME="john:#31&3*J"
curl -d -u "${CURLNAME}" https://www.example.com
If password has the special characters in it, just round the password with the single quote it will work.
curl -u username:'this|!Pa&*12' --request POST https://www.example.com
I did this
~]$ export A=g
~]$ export B=!
~]$ export C=nger
curl http://<>USERNAME<>1:$A$B$C#<>URL<>/<>PATH<>/