- 论坛徽章:
- 0
|
抓包如下:
- POST /cgi-bin/fileupload?job=add HTTP/1.1\r\n
- Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
- application/x-shockwave-flash, application/msword, application/vnd.ms-
- excel, application/vnd.ms-powerpoint, */*\r\n
- Referer: [url]http://bbs.stu.edu.cn/cgi-bin/fileupload[/url]\r\n
- Accept-Language: zh-cn\r\n
- Content-Type: multipart/form-data;
- boundary=---------------------------7d91f129901cc\r\n
- Accept-Encoding: gzip, deflate\r\n
- User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;
- SV1; .NET CLR 2.0.50727)\r\n
- Host: bbs.stu.edu.cn\r\n
- Content-Length: 259560
- Connection: Keep-Alive\r\n
- Cache-Control: no-cache\r\n
- Cookie: utmpnum=1019; utmpkey=33895263; utmpuserid=yorks\r\n
- \r\n
- First boundary: -----------------------------7d91f129901cc\r\n
- Content-Disposition: form-data; name="upload_file"; filename="V:\yorks
- \Documents\kernel_dev_persons1.jpg"\r\n
- Content-Type: image/pjpeg\r\n\r\n
- Last boundary: \r\n-----------------------------7d91f129901cc--\r\n
复制代码
我用urllib2发送的时候通过抓包,发现和通过浏览器的不一样。不知道哪里出错了,麻烦各位帮忙看看。
fileObj=open(picturePath,"rb")
file=fileObj.read()
fileObj.close()
#BOUNDARY = mimetools.choose_boundary()
#print BOUNDARY
BOUNDAY = "---------------------------7d91f129901cc"
#print BOUNDAY
CRLF = '\r\n'
lines = []
lines.append('--'+BOUNDAY)
lines.append('Content-Disposition: form-data; name="upload_file"; filename="%s"' % picturePath)
lines.append('Content-Type: image/pjpeg'+CRLF)
lines.append('')
lines.append(file)
lines.append(BOUNDAY + '--')
lines.append('')
body = CRLF.join(lines)
#print body
uploadHeaders = {
'Accept':'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/msword, applic
ation/vnd.ms-excel, application/vnd.ms-powerpoint, */*',
'Referer':'http://bbs.stu.edu.cn/cgi-bin/fileupload',
'Accept-Language':'zh-cn',
'Content-Type':'multipart/form-data; boundary=%s' % BOUNDAY,
#'Accept-Encoding':'gzip, deflate',
'User-Agent':'Mozilla/5.0 (X11; U; Linux i686; zh-CN; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5',
'Host': 'bbs.stu.edu.cn',
'Content-Length':'%s' % len(body),
'Connection':'Keep-Alive',
'Cache-Control':'no-cache',
'Cookie':'utmpnum=%s; utmpkey=%s; utmpuserid=%s' % (utmpnum, utmpkey, utmpuserid),
}
print uploadHeaders
uploadURL = "http://bbs.stu.edu.cn/cgi-bin/fileupload?job=add"
request = urllib2.Request(url=uploadURL,headers=uploadHeaders, data=body)
conn = urllib2.urlopen(request)
header = str(conn.info())
res = conn.read()
|
|
|