1
0
mirror of https://github.com/scrapy/scrapy.git synced 2025-02-24 13:23:59 +00:00

fixed bug with FormRequest class which wasn't setting method=POST by default

This commit is contained in:
Pablo Hoffman 2009-05-07 00:36:39 -03:00
parent 33909e05b4
commit 426282bbc9
2 changed files with 2 additions and 0 deletions

View File

@ -30,6 +30,7 @@ class FormRequest(Request):
items = formdata.iteritems() if isinstance(formdata, dict) else formdata
query = [(unicode_to_str(k, self.encoding), _unicode_to_str(v, self.encoding))
for k, v in items]
self.method = 'POST'
self.body = urllib.urlencode(query, doseq=1)
self.headers['Content-Type'] = 'application/x-www-form-urlencoded'

View File

@ -184,6 +184,7 @@ class FormRequestTest(unittest.TestCase):
# using default encoding (utf-8)
data = {'one': 'two', 'price': '\xc2\xa3 100'}
r2 = FormRequest("http://www.example.com", formdata=data)
self.assertEqual(r2.method, 'POST')
self.assertEqual(r2.encoding, 'utf-8')
self.assertEqual(r2.body, 'price=%C2%A3+100&one=two')
self.assertEqual(r2.headers['Content-Type'], 'application/x-www-form-urlencoded')