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

Otto otto at ottodestruct.com
Thu Jan 23 21:17:34 UTC 2014


When you're sending to an https URL (I noticed that the ssl flag is
on), then the WP_Http_Streams must find that a) the openssl extension
is loaded and b) the openssl_x509_parse function exists. Otherwise it
can't do ssl certificate verification.

So check those, see if the openssl extension is enabled on the system.
Curl doesn't need it because it does its own certificate verification.

To check this in code, you can use the wp_http_supports function. Pass
it the $args array and the URL you're making the call to. If it
returns false, then the system couldn't find a transport to handle
that type of remote call.

-Otto


On Thu, Jan 23, 2014 at 2:50 PM, Mike Walsh <mpwalsh8 at gmail.com> wrote:
> 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
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers


More information about the wp-hackers mailing list