I am trying to automate few http requests where, I have following POST call data which i captured from the web :
Method: POST Request Header :
POST /cgi-bin/auto_dispatch.cgi HTTP/1.1 Host: 10.226.45.6 Connection: keep-alive Content-Length: 244 Cache-Control: max-age=0 Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36 Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryhwDXAifvLs48E95A Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8 Referer: http://10.226.45.6/auto_dispatch.html Accept-Encoding: gzip, deflate Accept-Language: en-US,en;q=0.8,kn;q=0.6 Cookie: TWIKISID=dce9a6aa10e33b708f5bbc2912f781ab
payload :
------WebKitFormBoundaryhwDXAifvLs48E95A Content-Disposition: form-data; name="taskid"
123 ------WebKitFormBoundaryhwDXAifvLs48E95A Content-Disposition: form-data; name="Submit"
Submit Form ------WebKitFormBoundaryhwDXAifvLs48E95A--
MY script is as follows :
import httplib, urllib
def printText(txt):
lines = txt.split('\n')
for line in lines:
print line.strip()
params = urllib.urlencode({'@taskid': 12524, '@Submit': 'Submit Form'})
headers = {"Content-type": "multipart/form-data", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"}
conn = httplib.HTTPConnection("10.226.45.6", 80)
conn.request("POST", "auto_dispatch.html", params, headers)
response = conn.getresponse()
print response.status, response.reason
printText (response.read())
conn.close()
I am getting the following error :
400 Bad Request 400 Bad Request Bad Request Your browser sent a request that this server could not understand.
Please help me to form a proper request .