Opened 9 years ago
Closed 9 years ago
#37618 closed defect (bug) (duplicate)
String `$args['body']` passed to`WP_Http::get()` is lost, generates warning
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | 4.6 |
| Component: | HTTP API | Keywords: | |
| Focuses: | Cc: |
Description
Calling wp_remote_get( 'https://www.example.com', array( 'body' => 'foo' ) ) eventually passes 'foo' to http_build_query(), generating a warning: Parameter 1 expected to be Array or Object. Incorrect value given in /wp-includes/Requests/Transport/cURL.php on line 507 (or /wp-includes/Requests/Transport/fsockopen.php on line 353).
As far as I can tell, the 'body' value is also not included in the eventual request, but it is included with the same wp_remote_get() in 4.5.3.
I'm not comfortable enough with the HTTP API changes in this cycle to attempt a patch, if one is warranted.
Change History (6)
#3
@
9 years ago
AFAICT, the culprit is here:
// Setup arguments
$headers = $r['headers'];
$data = $r['body'];
$type = $r['method'];
It's just passed as the string all the way down.
Using:
wp_remote_get( 'http://example.com', array( 'body' => array( 'foo' ) ) );
resolves the warnings, however there are probably several plugins in the wild that use this.
I'm not extremely familiar with the Requests library, so I'm unsure what the path forward should be. Maybe a _doing_it_wrong, maybe just detecting a string and shoving it into an array, maybe both. ¯\_(ツ)_/¯
#4
@
9 years ago
- Keywords dev-feedback added
- Priority changed from normal to high
@rmccue @dd32 Please look into this ASAP. We want to release a RC today. Thanks!
#6
@
9 years ago
- Keywords dev-feedback removed
- Milestone 4.6 deleted
- Priority changed from high to normal
- Resolution set to duplicate
- Status changed from new to closed
WordPress 4.5:
$ wp core version
4.5.4-alpha-38000-src
$ wp shell
wp> wp_remote_get( 'https://www.example.com', array( 'body' => 'foo' ) );
=> phar:///usr/local/bin/wp/php/WP_CLI/REPL.php:43:
array(5) {
'headers' =>
array(5) {
'content-type' =>
string(9) "text/html"
'content-length' =>
string(3) "349"
'connection' =>
string(5) "close"
'date' =>
string(29) "Wed, 10 Aug 2016 09:17:47 GMT"
'server' =>
string(15) "ECSF (iad/19AC)"
}
'body' =>
string(349) "<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>400 - Bad Request</title>
</head>
<body>
<h1>400 - Bad Request</h1>
</body>
</html>
"
'response' =>
array(2) {
'code' =>
int(400)
'message' =>
string(11) "Bad Request"
}
'cookies' =>
array(0) {
}
'filename' =>
NULL
}
Trunk:
$ wp core version
4.7-alpha-38178-src
$ wp shell
wp> wp_remote_get( 'https://www.example.com', array( 'body' => 'foo' ) );
PHP Warning: http_build_query(): Parameter 1 expected to be Array or Object. Incorrect value given in phar:///usr/local/bin/wp/vendor/rmccue/requests/library/Requests/Transport/cURL.php on line 329
PHP Stack trace:
PHP 1. {main}() /usr/local/bin/wp:0
PHP 2. include() /usr/local/bin/wp:4
PHP 3. include() phar:///usr/local/bin/wp/php/boot-phar.php:5
PHP 4. WP_CLI\Runner->start() phar:///usr/local/bin/wp/php/wp-cli.php:21
PHP 5. WP_CLI\Runner->_run_command() phar:///usr/local/bin/wp/php/WP_CLI/Runner.php:906
PHP 6. WP_CLI\Runner->run_command() phar:///usr/local/bin/wp/php/WP_CLI/Runner.php:319
PHP 7. WP_CLI\Dispatcher\Subcommand->invoke() phar:///usr/local/bin/wp/php/WP_CLI/Runner.php:312
PHP 8. call_user_func:{phar:///usr/local/bin/wp/php/WP_CLI/Dispatcher/Subcommand.php:372}() phar:///usr/local/bin/wp/php/WP_CLI/Dispatcher/Subcommand.php:372
PHP 9. WP_CLI\Dispatcher\CommandFactory->WP_CLI\Dispatcher\{closure}() phar:///usr/local/bin/wp/php/WP_CLI/Dispatcher/Subcommand.php:372
PHP 10. call_user_func:{phar:///usr/local/bin/wp/php/WP_CLI/Dispatcher/CommandFactory.php:67}() phar:///usr/local/bin/wp/php/WP_CLI/Dispatcher/CommandFactory.php:67
PHP 11. Shell_Command->__invoke() phar:///usr/local/bin/wp/php/WP_CLI/Dispatcher/CommandFactory.php:67
PHP 12. WP_CLI\REPL->start() phar:///usr/local/bin/wp/php/commands/shell.php:55
PHP 13. eval() phar:///usr/local/bin/wp/php/WP_CLI/REPL.php:37
PHP 14. wp_remote_get() phar:///usr/local/bin/wp/php/WP_CLI/REPL.php(37) : eval()'d code:1
PHP 15. WP_Http->get() /Users/Dominik/Development/WordPress/vagrant/www/wp-develop/svn/src/wp-includes/http.php:170
PHP 16. WP_Http->request() /Users/Dominik/Development/WordPress/vagrant/www/wp-develop/svn/src/wp-includes/class-http.php:591
PHP 17. Requests->request() /Users/Dominik/Development/WordPress/vagrant/www/wp-develop/svn/src/wp-includes/class-http.php:366
PHP 18. Requests_Transport_cURL->request() phar:///usr/local/bin/wp/vendor/rmccue/requests/library/Requests.php:317
PHP 19. Requests_Transport_cURL->setup_handle() phar:///usr/local/bin/wp/vendor/rmccue/requests/library/Requests/Transport/cURL.php:91
PHP 20. Requests_Transport_cURL->format_get() phar:///usr/local/bin/wp/vendor/rmccue/requests/library/Requests/Transport/cURL.php:229
PHP 21. http_build_query() phar:///usr/local/bin/wp/vendor/rmccue/requests/library/Requests/Transport/cURL.php:329
=> phar:///usr/local/bin/wp/php/WP_CLI/REPL.php:43:
array(6) {
'headers' =>
class Requests_Utility_CaseInsensitiveDictionary#1058 (1) {
protected $data =>
array(13) {
'content-encoding' =>
string(4) "gzip"
'accept-ranges' =>
string(5) "bytes"
'cache-control' =>
string(14) "max-age=604800"
'content-type' =>
string(9) "text/html"
'date' =>
string(29) "Wed, 10 Aug 2016 08:49:08 GMT"
'etag' =>
string(16) ""359670651+gzip""
'expires' =>
string(29) "Wed, 17 Aug 2016 08:49:08 GMT"
'last-modified' =>
string(29) "Fri, 09 Aug 2013 23:54:35 GMT"
'server' =>
string(14) "ECS (iad/18CB)"
'vary' =>
string(15) "Accept-Encoding"
'x-cache' =>
string(3) "HIT"
'x-ec-custom-error' =>
string(1) "1"
'content-length' =>
string(3) "606"
}
}
'body' =>
string(1270) "<!doctype html>
<html>
<head>
<title>Example Domain</title>
<meta charset="utf-8" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
body {
background-color: #f0f0f2;
margin: 0;
padding: 0;
font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
}
div {
width: 600px;
margin: 5em auto;
"...
'response' =>
array(2) {
'code' =>
int(200)
'message' =>
string(2) "OK"
}
'cookies' =>
array(0) {
}
'filename' =>
NULL
'http_response' =>
class WP_HTTP_Requests_Response#1055 (5) {
protected $response =>
class Requests_Response#1056 (9) {
public $body =>
string(1270) "<!doctype html>
<html>
<head>
<title>Example Domain</title>
<meta charset="utf-8" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
body {
background-color: #f0f0f2;
margin: 0;
padding: 0;
font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
}
div {
width: 600px;
margin: 5em auto;
"...
public $raw =>
string(1642) "HTTP/1.1 200 OK
Content-Encoding: gzip
Accept-Ranges: bytes
Cache-Control: max-age=604800
Content-Type: text/html
Date: Wed, 10 Aug 2016 08:49:08 GMT
Etag: "359670651+gzip"
Expires: Wed, 17 Aug 2016 08:49:08 GMT
Last-Modified: Fri, 09 Aug 2013 23:54:35 GMT
Server: ECS (iad/18CB)
Vary: Accept-Encoding
X-Cache: HIT
x-ec-custom-error: 1
Content-Length: 606
<!doctype html>
<html>
<head>
<title>Example Domain</title>
<meta charset="utf-8" />
<meta http-equiv="Content-type" content="t"...
public $headers =>
class Requests_Response_Headers#1057 (1) {
...
}
public $status_code =>
int(200)
public $success =>
bool(true)
public $redirects =>
int(0)
public $url =>
string(23) "https://www.example.com"
public $history =>
array(0) {
...
}
public $cookies =>
class Requests_Cookie_Jar#1054 (1) {
...
}
}
protected $filename =>
NULL
public $data =>
NULL
public $headers =>
NULL
public $status =>
NULL
}
}
Quoting rmccue:
It'd be nice if Requests didn't trigger a warning, but the usage is incorrect here.
Closing as duplicate of #37364.
Moving to 4.6 for further review.