Skip to content

Commit 20ceedc

Browse files
author
Sandeep parmar
committed
Curl --data-urlencode does not encode name of the data of the form name=content
Added new function using jq filter to encode custom string
1 parent 785f548 commit 20ceedc

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

snippets/curl/get_nb_images.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ data=$(jq --arg name $username --arg pass $password --arg dname $domainname --ar
8484
jwt=$(curl -k -X POST $uri -H $content_header -d "$data" | jq --raw-output '.token')
8585

8686
param1="filter=policyType eq 'Standard'"
87-
param2="page[limit]=10"
87+
88+
### To use filter page[limit] in URI, The key 'page[limit]' must be url encoded already. ###
89+
### Curl --data-urlencode encodes only the content part of the data of the form 'name=content' ###
90+
param2="$(uriencode 'page[limit]')=10" #op: page%5Blimit%5D=10
8891

8992
##############jobs##############
9093

snippets/curl/get_nb_jobs.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,17 @@ parseArguments()
6767
fi
6868
}
6969

70+
uriencode()
71+
{
72+
jq -nr --arg v "$1" '$v|@uri';
73+
}
74+
7075
###############main#############
7176

7277
parseArguments "$@"
7378

7479
basepath="https://$master_server:$port/netbackup"
75-
content_header='content-type:application/json'
80+
content_header='content-type:application/json;charset=utf-8'
7681

7782
##############login#############
7883

@@ -84,14 +89,17 @@ data=$(jq --arg name $username --arg pass $password --arg dname $domainname --ar
8489
jwt=$(curl -k -X POST $uri -H $content_header -d "$data" | jq --raw-output '.token')
8590

8691
param1="filter=jobType eq 'BACKUP'"
87-
param2="page[limit]=10"
92+
93+
### To use filter page[limit] in URI, The key 'page[limit]' must be url encoded already. ###
94+
### Curl --data-urlencode encodes only the content part of the data of the form 'name=content' ###
95+
param2="$(uriencode 'page[limit]')=10" #op: page%5Blimit%5D=10
8896

8997
##############jobs##############
9098

9199
auth_header="authorization:$jwt"
92100
uri="$basepath/admin/jobs"
93101

94-
curl --insecure --request GET --globoff --get $uri -H $content_header -H $auth_header \
102+
curl --verbose --insecure --request GET --get $uri -H $content_header -H $auth_header \
95103
--data-urlencode "$param1" \
96104
--data-urlencode "$param2" \
97105
| \

0 commit comments

Comments
 (0)