Discussion:
Sending checkbox parameters to a non-PHP script using wp_remote_post - revisited
Mike Walsh
2014-01-23 20:50:20 UTC
Permalink
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 - ***@gmail.com
Otto
2014-01-23 21:17:34 UTC
Permalink
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
Post by Mike Walsh
About two years ago I came to wp-hackers with a problem I was facing
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
[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
--
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Mike Walsh
2014-01-24 02:59:21 UTC
Permalink
Being able to test for the transport to work would be wonderful because I
could flag a problem. Unfortunately, wp_http_transports() is returning a 1
(true) even though it doesn't actually work:

[23-Jan-2014 21:01:51 UTC] wpgform-core.php::1753: -->
https://docs.google.com/forms/d/16Uw3Xw9xX2i08w9FGk0M5GOlR8lsUBglLiUA6cJzy2s/formResponse
[23-Jan-2014 21:01:51 UTC] wpgform-core.php::1754: --> wp_http_supports:
1

According to phpinfo(), openssl is enabled on this server so the response
from wp_http_supports() is correct. It just doesn't work. :-(

Mike
Post by Otto
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
Post by Mike Walsh
About two years ago I came to wp-hackers with a problem I was facing
http://lists.automattic.com/pipermail/wp-hackers/2012-January/042163.html
).
Post by Mike Walsh
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
Post by Mike Walsh
body parameter as a named array instead of a string (as recommended in
the
Post by Mike Walsh
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
Post by Mike Walsh
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
Post by Mike Walsh
[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
Post by Mike Walsh
[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
Post by Mike Walsh
[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
Post by Mike Walsh
[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
Post by Mike Walsh
[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
Post by Mike Walsh
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
Post by Mike Walsh
[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
Post by Mike Walsh
Hopefully someone can see something I am not seeing!
Thanks,
Mike
--
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
--
Mike Walsh - ***@gmail.com
Mike Walsh
2014-01-24 14:31:44 UTC
Permalink
To add a little more information, I did some testing with older versions of
WordPress in combination with the http_api_transports to force a specific
transport ('streams', 'fsockopen', and 'curl'). I found the following
results:

3.6.1: cURL: Success fsockopen: Success streams: Success
3.7.1: cURL: Success fsockopen: Fail streams: Fail
3.8.1: cURL: Success fsockopen: Fail streams: Fail

Something clearly changed with the streams and fsockopen transports between
3.6.1 and 3.7.1. A diff of the class-http.php file shows the change was
substantial as the files are significantly different.

At this point I have concluded that my plugin will only work with sites
where cURL is available.

Mike
Post by Mike Walsh
Being able to test for the transport to work would be wonderful because I
could flag a problem. Unfortunately, wp_http_transports() is returning a 1
[23-Jan-2014 21:01:51 UTC] wpgform-core.php::1753: -->
https://docs.google.com/forms/d/16Uw3Xw9xX2i08w9FGk0M5GOlR8lsUBglLiUA6cJzy2s/formResponse
1
According to phpinfo(), openssl is enabled on this server so the response
from wp_http_supports() is correct. It just doesn't work. :-(
Mike
Post by Otto
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
Post by Mike Walsh
About two years ago I came to wp-hackers with a problem I was facing
http://lists.automattic.com/pipermail/wp-hackers/2012-January/042163.html
).
Post by Mike Walsh
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
Post by Mike Walsh
being submitted to Google.
In looking into it, the user provided me with a patch which constructed
the
Post by Mike Walsh
body parameter as a named array instead of a string (as recommended in
the
Post by Mike Walsh
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
Post by Mike Walsh
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
Post by Mike Walsh
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
Post by Mike Walsh
[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
Post by Mike Walsh
[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
Post by Mike Walsh
[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
Post by Mike Walsh
[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
Post by Mike Walsh
[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
Post by Mike Walsh
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
Post by Mike Walsh
[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
Post by Mike Walsh
Hopefully someone can see something I am not seeing!
Thanks,
Mike
--
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
--
--
Mike Walsh - ***@gmail.com
Loading...