[wp-hackers] Sending checkbox parameters to a non-PHP script using wp_remote_post - revisited

Mike Walsh mpwalsh8 at gmail.com
Thu Jan 23 20:50:20 UTC 2014


About two years ago I came to wp-hackers with a problem I was facing
posting data to Google Forms using wp_remote_post() (see this thread:
http://lists.automattic.com/pipermail/wp-hackers/2012-January/042163.html).

The solution at the end of the thread to manually construct the body
parameters as a string is what I've been doing and has worked very well
until recently when I had a bug report from a user telling me nothing was
being submitted to Google.

In looking into it, the user provided me with a patch which constructed the
body parameter as a named array instead of a string (as recommended in the
Codex).  The problem with this solution is it doesn't work for my
application because it ends up making a call to http_build_query() which in
turn creates the query string for the checkboxes in PHP syntax (as would
expect) where as I need them in Python synxtax for submitting to Google
Docs.

I was able to make my own call to http_build_query() and post-process the
result to fix the chekbox parameters.  Now I am finding that if I submit
the result to Google using the cURL transport it works fine however if I
submit it using the Streams or fsockopen()  transport it fails.

I beauty of the HTTP API was that I shouldn't have to worry about what
transport is available to WordPress but I am finding that not to be the
case.

I am testing my plugin on Windows w/ IIS and PHP 5.3.13 and Ubuntu 3.11
with PHP 5.5.3-1.

I supposed I can test for cURL as warn the user at plugin activation but
I'd rather try and resolve this if possible.

Here is what the HTTP shows me when using the cURL transport.

[23-Jan-2014 19:07:18 UTC] class-http.php::270 -->  WP_HTTP_curl
[23-Jan-2014 19:07:18 UTC] class-http.php::271 -->  Array
(
    [method] => POST
    [timeout] => 0
    [redirection] => 5
    [httpversion] => 1.0
    [user-agent] => WordPress/3.8; http://localhost
    [reject_unsafe_urls] =>
    [blocking] => 1
    [headers] => Array
        (
            [Accept-Encoding] => deflate;q=1.0, compress;q=0.5, gzip;q=0.5
            [Content-Length] => 129
        )

    [cookies] => Array
        (
        )

    [body] =>
entry.516744731=C-3&entry.516744731=D-4&entry.1595909349=Mike&draftResponse=%5B%2C%2C%220%22%5D%0D%0A&pageHistory=0&submit=Submit
    [compress] =>
    [decompress] => 1
    [sslverify] =>
    [sslcertificates] =>
/var/www/wordpress/wp-includes/certificates/ca-bundle.crt
    [stream] =>
    [filename] =>
    [limit_response_size] =>
    [_redirection] => 5
    [ssl] => 1
    [local] =>
)

[23-Jan-2014 19:07:19 UTC] class-http.php::209 --->
 entry.516744731=C-3&entry.516744731=D-4&entry.1595909349=Mike&draftResponse=%5B%2C%2C%220%22%5D%0D%0A&pageHistory=0&submit=Submit

Here is the same request using the Streams transport:

[23-Jan-2014 19:09:35 UTC] class-http.php::270 -->  WP_HTTP_streams
[23-Jan-2014 19:09:35 UTC] class-http.php::271 -->  Array
(
    [method] => POST
    [timeout] => 0
    [redirection] => 5
    [httpversion] => 1.0
    [user-agent] => WordPress/3.8; http://localhost
    [reject_unsafe_urls] =>
    [blocking] => 1
    [headers] => Array
        (
            [Accept-Encoding] => deflate;q=1.0, compress;q=0.5, gzip;q=0.5
            [Content-Length] => 129
        )

    [cookies] => Array
        (
        )

    [body] =>
entry.516744731=C-3&entry.516744731=D-4&entry.1595909349=Mike&draftResponse=%5B%2C%2C%220%22%5D%0D%0A&pageHistory=0&submit=Submit
    [compress] =>
    [decompress] => 1
    [sslverify] =>
    [sslcertificates] =>
/var/www/wordpress/wp-includes/certificates/ca-bundle.crt
    [stream] =>
    [filename] =>
    [limit_response_size] =>
    [_redirection] => 5
    [ssl] => 1
    [local] =>
)

[23-Jan-2014 19:09:36 UTC] class-http.php::845 --->  Resource id #11
[23-Jan-2014 19:09:36 UTC] class-http.php::846 --->  POST
/forms/d/16Uw3Xw9xX2i08w9FGk0M5GOlR8lsUBglLiUA6cJzy2s/formResponse HTTP/1.0
Host: docs.google.com
User-agent: WordPress/3.8; http://localhost
Accept-Encoding: deflate;q=1.0, compress;q=0.5, gzip;q=0.5
Content-Length: 129

entry.516744731=C-3&entry.516744731=D-4&entry.1595909349=Mike&draftResponse=%5B%2C%2C%220%22%5D%0D%0A&pageHistory=0&submit=Submit
[23-Jan-2014 19:09:36 UTC] class-http.php::209 --->
 entry.516744731=C-3&entry.516744731=D-4&entry.1595909349=Mike&draftResponse=%5B%2C%2C%220%22%5D%0D%0A&pageHistory=0&submit=Submit

Hopefully someone can see something I am not seeing!

Thanks,

Mike
-- 
Mike Walsh - mpwalsh8 at gmail.com


More information about the wp-hackers mailing list