无法通过Curl POST命令传递数据。
代码:
printf "\nGet given User details :\n"
curl -s -b ${COOKIE_FILE} -c ${COOKIE_FILE} 'https://api.xxxx.xxxx.com/sso/user?email='${USER_EMAIL} |python -m json.tool > output.txt
user_id=$(cat output.txt | grep -w "id" | awk -F ':' {'print $2'} | sed -e 's|[," ]||g');
echo "User ID for given add User: $user_id"
printf "\nGet given Role/Group details :\n"
curl -s -b ${COOKIE_FILE} -c ${COOKIE_FILE} 'https://api.xxxx.xxxx.com/role?name='${ROLE_NAME} | python -m json.tool > output_roles.txt
role_id=$(cat output_roles.txt | grep -w "id" | awk -F ':' {'print $2'} | sed -e 's|[," ]||g');
printf "\nAdding User to given Group :\n"
curl -s -b ${COOKIE_FILE} -c ${COOKIE_FILE} -X POST -data '{"role_users":"$role_id","user_roles":"$user_id"}' 'https://api.xxx.xxxx.com/rolesusers'
Curl POST命令不适用于我。它不会给我任何错误,也不会给我带来任何变化。
当我传递硬编码值时,Curl命令起作用。
curl -s -b ${COOKIE_FILE} -c ${COOKIE_FILE} -X POST -H "Accept: Application/json" -H "Content-Type: application/json" --data '{"role_users":22, "user_roles":99}' 'https://api.xxx.xxxx.com/rolesusers'
知道了-通过添加'
curl -s -b ${COOKIE_FILE} -c ${COOKIE_FILE} -X POST -H "Accept: Application/json" -H "Content-Type: application/json" --data '{"role_users":"'$role_id'", "user_roles":"'$user_id'"}' 'https://api.xxx.xxxx.com/rolesusers' > output_add.txt