I am trying to send a post request using curl command in shell script.
When i run this curl command in terminal, it is working fine.
curl -d '{"DataArr":[{"serialno":"ab1","filePath":"/home/name/notes1"}]}' -H 'Content-Type: application/json' -H 'Authorization: tasfdgfdhh...' http://localhost:8081/create
The same I am trying to run this as shell script file, it is hitting the server but the data format is not expected. The array bracket is converting as :" or something like :{ . I tried so many times with different possibilities but i do not understand how to prepare correct request. Below is the code and the response at server side.
I am using looping statement to simulate multiple requests,
code:
#!/bin/bash
echo "hello welcome to testing";
token=asdghadjakalskl.....
requestNo=10
i=0
sNo=(ab1 ab2 ab3 ab4 ab5)
fn=(notes1 Pictures/crop.jpeg Pictures/cat.jpeg Pictures/mountain.jpg Pictures/magic.jpeg Pictures/tree.jpg)
echo $1
for (( i=0; i< $1;i++ ))
do
# echo "welcome inside the loop $s"
echo ${sNo[i%5]} ${fn[i%6]}
f="/home/name/${fn[i%6]}"
# echo $token
echo file $f
echo $i request sent
curl -d '{"DataArr":[{"serialno":'${sNo[i%5]}',"filePath":'$f'}]}' -H "'Content-Type: application/json'" -H 'Authorization: '$token'' http://localhost:8080/create
done
At server side,
{"{\"qualityDataArr\":":{"{\"serialNumberCustomer\":ab1,\"filePath\":/home/name/notes1}":""}}
Please guide me. Thank you!