zephor
zephor

Reputation: 747

Is there any way to async post some data with twisted?

client.getPage('url', method='POST',
               postdata=urllib.urlencode({'doc': {somedata}}))

this isn't work for me and I got "empty data" in response. Seems postdata is just a joke

Upvotes: 3

Views: 324

Answers (1)

MartyIX
MartyIX

Reputation: 28686

It works for me in Python2 when I add application/x-www-form-urlencoded:

import urllib
from twisted.internet import reactor
from twisted.web import client

client.getPage('http://requestb.in/vvs5qdvv', method='POST', 
               headers={'Content-Type': 'application/x-www-form-urlencoded'}, 
               postdata=urllib.urlencode({'doc':'data'}));

reactor.run()

See sent data here: http://requestb.in/vvs5qdvv?inspect

Upvotes: 3

Related Questions