我正在尝试向此页面发送POST请求:
POST /fr/searchfor/ HTTP/1.1
Host: url.be
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate, br
Referer: same
Cookie: __utma=264609361.761154405.1479580795.1479580795.1479580795.1; __utmz=264609361.1479580795.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); PHPSESSID=290392ec3af681078222b6e40f8e6c9e
DNT: 1
Connection: keep-alive
Upgrade-Insecure-Requests: 1
Content-Type: application/x-www-form-urlencoded
Content-Length: 68
search_name=dubois&search_place=&search_place_min=&search_place_max=
HTTP/1.1 200 OK
Date: Sun, 20 Nov 2016 06:10:45 GMT
Server: Apache
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 5554
Content-Type: text/html; charset=utf-8
Keep-Alive: timeout=5, max=150
Connection: Keep-Alive
这是我的代码,我已经尝试了几种解决方案,但我总是有相同的回复: 400错误请求
data = urllib.urlencode({'search_name' : 'dubois', 'search_place' : '','search_place_min':'', 'search_place_max' : ''})
h = httplib.HTTPConnection("www.url.be")
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0'
,'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language': 'fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3',
'Accept-Encoding': 'gzip, deflate, br',
'Referer': 'url',
'Cookie': '__utma=264609361.761154405.1479580795.1479580795.1479580795.1; __utmz=264609361.1479580795.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); PHPSESSID=290392ec3af681078222b6e40f8e6c9e',
'Connection': 'keep-alive',
'Upgrade-Insecure-Requests': '1',
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': '78'
}
u = urllib2.urlopen('see URL ', data)
h.request('POST', '/fr/searchfor/', data, headers)
r = h.getresponse()
decompressed_data=zlib.decompress(r.read(), 16+zlib.MAX_WBITS)
print decompressed_data