use wget to keep session cookie and use form-based file upload

#!/bin/sh
wget --no-check-certificate -O file1 --save-cookies cookies.txt --keep-session-cookies https://URL/
COOKIE=`cat cookies.txt tail -1 awk'{print$NF}'`
USER=admin
PASS=password
CORP=corpname
HASH=`echo -n $CORP$USER$PASS sha1sum awk '{print $1}'`
wget --debug --no-check-certificate -O file2 --load-cookies cookies.txt --post-data "LoginId=$USER&Password=$PASS&Corporation=$CORP&sessionid=${COOKIE}" https://URL/

wget --debug --no-check-certificate -O file3 --load-cookies cookies.txt --header="Content-Type: multipart/form-data; boundary=FILEUPLOAD" --post-file postfile https://url/

sleep 10

wget --debug --no-check-certificate -O file4 --load-cookies cookies.txt https://url2/
wget --debug --no-check-certificate -O file5 --load-cookies cookies.txt --post-data "module=a&screen=b&action=c" https://url3/

note:
1. use httpliveheader firefox addon to get all the http header and request/response
2. sleep 10 to wait for the processing finish
3. --save-cookies cookies.txt --keep-session-cookies -> make multiple wget command to be like in the same browser session.
4. for upload text file, that's to say, use ' form-based file upload in html', the RFC is at
http://www.faqs.org/rfc/rfc1867.html
5. for postfile content:

-bash-3.1# more postfile
--FILEUPLOAD
Content-Disposition: form-data; name="module"
a
--FILEUPLOAD
Content-Disposition: form-data; name="screen"
b
--FILEUPLOAD
Content-Disposition: form-data; name="action"
c
--FILEUPLOAD
Content-Disposition: form-data; name="description"
test
--FILEUPLOAD
Content-Disposition: form-data; name="fileName"; filename="data.txt"Content-Type: text/plain
20070201 0758 a1000 I
20070201 2031 a1000 O
--FILEUPLOAD--
note: with --FILEUPLOAD, the separator is just 'FILEUPLOAD', and the last line is --FILEUPLOAD--

No comments:

Post a Comment