Setup
In a Bash script I'm Using curl to POST the contents of a JSON file to a RESTful API running on tomcat behind nginx.
This POST also requires basic auth with 3 different query parameters on the end of the URL.
while IFS= read -d '' -r file; do
base=$(basename "$file")
datetime=$(find $file -maxdepth 0 -printf "%TY/%Tm/%Td %TH:%TM:%.2TS")
username="vangeeij"
curl -vX POST -H "Content-Type: application/json" -H "Cache-Control: no-cache" \
-u username:password \
-d @"$file" \
"http://192.168.105.10/homeaccess/services/aCStats/uploadData?username=$username&filename=$base" \
--data-urlencode datetime=$datetime
#sudo mv "$file" /home/vangeeij/acserver/resultsOld
done < <(sudo find . -type f -print0)
Results/Problem
as can be seen in the output from curl, the URL does NOT have the datetime= parameter attached tot he end of the URL
* Connected to 192.168.105.10 (192.168.105.10) port 80 (#0)
* Server auth using Basic with user 'username'
> POST /homeaccess/services/aCStats/uploadData?username=username&filename=2017_3_1_8_50_RACE.json HTTP/1.1
> Host: 192.168.105.10
Question
What is the proper syntax to accomplish what I'm trying here. Curl POST of JSON file to URL with the attachment of parameters to the URL, at least one of which HAS to be URLEncoded?
datetime=$datatimebe part of the url query string as&datetime=$datetimeif you want to pass it to the server?GETrequest. The various--dataoptions place the parameters in the body of the request, which anything processing aPOSTrequest is certain to look for. You should even be able to add--data username="$username"andfilename="$base"in place of?username=$username&filename=$baseand get the same result.