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

Aaron DeVore aaron.devore at gmail.com
Wed Aug 6 23:50:33 EDT 2008


Yet again, I managed to catch what I was doing wrong about 1 minute after I
clicked the "Send" button. It turns out that I had written another function
incorrectly. Thanks for the help guys!

-Aaron DeVore

On Wed, Aug 6, 2008 at 7:49 PM, Aaron DeVore <aaron.devore at gmail.com> wrote:

> Oops, I should have checked that code example a bit better. The line shou=
ld
> read (with urllib.urlencode imported):
>
> HTTPClientFactory(url, postdata=3Durlencode(postdata), headers=3D{
> 'Content-Type': 'application/x-www-form-urlencoded; charset=3Dutf-8'})
>
>
> On Wed, Aug 6, 2008 at 2:17 PM, Jean-Paul Calderone <exarkun at divmod.com>w=
rote:
>
>> 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=3D"post". I pick=
ed
>>> 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:
>>>
>>> <code>
>>> post =3D {}
>>> post['name'] =3D val
>>>
>>> clientFactory =3D HTTPClientFactory(url, method=3D"POST",
>>> headers=3D{'Content-Type': "application/x-www-form-urlencoded;
>>> charset=3Dutf-8"})
>>> reactory.connectTCP(urlparse(self.currentRequestURL)[1], 80,
>>> self.currentClientFactory)
>>>
>>> </code>
>>>
>>> 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=B4 parameter.  You also need to encode this yourself,
>> since `postdata=B4 accepts a string, not a dict.
>>
>> Jean-Paul
>>
>> _______________________________________________
>> Twisted-web mailing list
>> Twisted-web at twistedmatrix.com
>> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-web/attachments/20080806/9c=
af41ee/attachment.htm


More information about the Twisted-web mailing list