How to pass in multiple --data in Ansible using uri - ansible

I'm trying to come up with equivalent Curl command in Ansible using the uri module to no avail
curl 'https://URL --data 'a=1234' --data 's=4321'
In ansible:
- uri:
url: https://URL
method: PUT
body:
a: 1234
s: 4321
status_code: 200
headers:
Content-Type: "application/x-www-form-urlencoded"
I get a response back that command is invalid meaning my Ansible task doesn't work but using the equivalent curl command works fine.

Related

Duckling send JSON to parse method ('Need a 'text' parameter to parse' error)

I work with Duckling, whish works on my local machine on port 8000. via CURL. Requests of the following type:
curl -X POST https://0.0.0.0:8000/parse -d 'locale=en_GB&text=tomorrow at eight'
executed successfully.
But when I do so:
curl -X POST https://0.0.0.0:8000/parse -H 'Content-Type: application/json' -d '{"locale": "en_GB", "text": "tomorrow at eight"}'
The HTTP 422 code is returned with the message "Need a 'text' parameter to parse".
How to correctly pass JSON to Duckling?

parse error: Invalid numeric literal at line 1, column 7

I am trying to call an API using Curl. The request was timing out after 60 secs due to TCP Timeout. I added "-H "Connection: keep-alive" -H "Keep-Alive: timeout=90, max=100" to the existing code.
curl -s -X POST -u $regressionTestAuthToken -H Content-Type: application/json -H Accept: application/json -H "Connection: keep-alive" -H "Keep-Alive: timeout=90, max=100" $URL -d#"${WORKSPACE}"/tmp.json > "${WORKSPACE}"/out.json
After adding the Connection Keep-Alive, I am getting a parse error
parse error: Invalid numeric literal at line 1, column 7
Can someone help me to triage this issue?

How to pass Headers and x-www-form-urlencoded body in Autocannon

I'm trying to pass Headers and x-www-form-urlencoded body in Autocannon POST request, but my response is always:
0 2xx responses, 5 non 2xx responses
Example from command line:
autocannon -c 1 -a 5 -H Authorization="Bearer xxxx",Content-Type="application/x-www-form-urlencoded" -b "Key"="Value" http://host.com:8080/path
Use -H flag for each header like this :
autocannon -c 1 -a 5 -H "Authorization":"Bearer xxxx" -H "Content-Type":"application/x-www-form-urlencoded" -b '{"Key"="Value"}'
http://host.com:8080/path
Let's say you have the following data and you want to make a POST request using x-www-form-urlencoded:
URL
https://api.something.com
Headers
Authorization: Bearer some-extra-long-uuid=
Content-Type: application/x-www-form-urlencoded
Body
field_1: value_1
field_2: value_2
For the above data, the autocannon CLI command would look something like below:
autocannon -m POST -H "Authorization":"Bearer some-extra-long-uuid=" -H "Content-Type":"application/x-www-form-urlencoded" -b "field_1=value_1&field_2=value_2" https://api.something.com

Curl call from Terminal and Shellscript is diffrent?

I am calling the same curl command once from terminal and once from Shellscript - but the outcome is different:
#!/usr/bin/env bash
url="dev.test.ch"
http="http://"
test="192.168.178.107"
curl -H "'Host: $url'" "$http$test"
echo "'Host: $url'" "$http$test"
and
curl -H 'Host: dev.test.ch' http://192.168.178.107
Once I get the NGINX Startpage (from Shellscript) and once the right response (HTML Page from my App)
Any ideas?
Stupid me -
curl -H 'Host: '$newline "$http$test"
the braces were the problem.
You can use curl with -v option to see what exactly HTTP request was sent to server. Problem that in your script you curl adds 'Host header.
With this line curl -H "'Host: $url'" "$http$test" it sends
> GET http://192.168.178.107/ HTTP/1.1
> Host: 192.168.178.107
> User-Agent: curl/7.49.1
> Accept: */*
> 'Host: dev.test.ch'
If you remove single qoutes curl -v -H "Host: $url" "$http$test" it will send proper request:
> GET http://192.168.178.107/ HTTP/1.1
> Host: dev.test.ch
> User-Agent: curl/7.49.1
> Accept: */*

Cannot extract data from an HTTP PUT request in Ruby

I am trying to implement a simple server in Ruby, but somehow I can't get the data from a put request.
curl request that I am making:
curl -v -X PUT localhost:2016/api/kill -d {"connId" : 1}
The server seems to be reading the request alright.
The code:
while line = socket.gets
puts line.chomp
request << line.chomp
break if line =~ /^\s*$/
end
produces the output:
PUT /api/kill HTTP/1.1
User-Agent: curl/7.35.0
Host: localhost:2016
Accept: */*
Content-Length: 7
Content-Type: application/x-www-form-urlencoded
But I don't see the data anywhere?
Am I supposed to see it?
Is something wrong with the curl request?
You need single quotes around the body.
curl -v -X PUT localhost:2016/api/kill -d '{"connId" : 1}'

Resources