首页 文章

httplib发布调用错误

提问于
浏览
0

我正在尝试自动化几个http请求,其中,我有以下从网络捕获的POST调用数据:

方法:POST请求标头:

POST /cgi-bin/auto_dispatch.cgi HTTP / 1.1主机:10.226.45.6连接:keep-alive内容长度:244 Cache-Control:max-age = 0 Upgrade-Insecure-Requests:1 User-Agent:Mozilla / 5.0 (Windows NT 6.3; WOW64)AppleWebKit / 537.36(KHTML,与Gecko一样)Chrome / 53.0.2785.143 Safari / 537.36内容类型:multipart / form-data; boundary = ---- WebKitFormBoundaryhwDXAifvLs48E95A接受: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

负载:

------ WebKitFormBoundaryhwDXAifvLs48E95A Content-Disposition:form-data; NAME = “任务id”

123 ------ WebKitFormBoundaryhwDXAifvLs48E95A Content-Disposition:form-data; NAME = “提交”

提交表格------ WebKitFormBoundaryhwDXAifvLs48E95A--

我的脚本如下:

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()

我收到以下错误:

400错误请求400错误请求错误请求您的浏览器发送了此服务器无法理解的请求 .

请帮我形成一个合适的要求 .

1 回答

相关问题