From a01077a8e9a634759e36f5f50b4e174c4e991e3d Mon Sep 17 00:00:00 2001 From: Jonathan Hodgson Date: Tue, 17 Dec 2019 12:30:12 +0000 Subject: [PATCH] Adds a script for turning an html form into a curl requst --- bin/.bin/webtest/formtocurl | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 bin/.bin/webtest/formtocurl diff --git a/bin/.bin/webtest/formtocurl b/bin/.bin/webtest/formtocurl new file mode 100755 index 00000000..30c60b66 --- /dev/null +++ b/bin/.bin/webtest/formtocurl @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +# Requires hq : https://github.com/coderobe/hq + +form=$(cat) +headers(){ + echo "$fields" | while read name; do + value=$(echo "$form" | hq "input[name=$name]" attr value) + if [ -z "$value" ]; then + value="" + fi + echo "-H '${name}=${value}'" + done | tr '\n' ' ' | sed 's/ $//' +} + +url=$(echo "$form" | hq form attr action) +method=$(echo "$form" | hq form attr method) +fields=$(echo "$form" | hq input attr name) + +curlHeaders=$(headers) +if [ -z "$method" ]; then + method="POST" +fi + +echo "curl -X $method $curlHeaders $url" + +#curlHeaders=$(echo "$fields" | sed 's/\(.*\)/-H '"'"'\1='"'"'/' | tr '\n' ' ')