[Twisted-web] Using HTTPClientFactory to send POST form data

Jean-Paul Calderone exarkun at divmod.com
Wed Aug 6 18:17:31 EDT 2008

On Wed, 6 Aug 2008 15:09:29 -0700, Aaron DeVore <aaron.devore at gmail.com> wrote:
>I'm working on a project that needs to send data in a fashion that is
>identical to what is sent via an HTML form with method="post". I picked
>HTTPClientFactory for the requests but I'm having a hard time figuring out
>how to send the post data. So far I have tried something approximately like:
>post = {}
>post['name'] = val
>clientFactory = HTTPClientFactory(url, method="POST",
>headers={'Content-Type': "application/x-www-form-urlencoded;
>reactory.connectTCP(urlparse(self.currentRequestURL)[1], 80,
>When I go to a PHP script that prints out the $_POST array it shows that the
>$_POST array is empty.
>What am I doing wrong? How would I go about solving the problem?

You didn't actually supply the post data to the HTTPClientFactory.
The default is to post an empty string.  You need to supply a value
for the `postdata´ parameter.  You also need to encode this yourself,
since `postdata´ accepts a string, not a dict.


More information about the Twisted-web mailing list