[wp-trac] [WordPress Trac] #37618: String `$args['body']` passed to`WP_Http::get()` is lost, generates warning

WordPress Trac noreply at wordpress.org
Wed Aug 10 09:24:56 UTC 2016


#37618: String `$args['body']` passed to`WP_Http::get()` is lost, generates warning
--------------------------+------------------------
 Reporter:  dlh           |       Owner:
     Type:  defect (bug)  |      Status:  closed
 Priority:  normal        |   Milestone:
Component:  HTTP API      |     Version:  trunk
 Severity:  normal        |  Resolution:  duplicate
 Keywords:                |     Focuses:
--------------------------+------------------------
Changes (by ocean90):

 * keywords:  dev-feedback =>
 * priority:  high => normal
 * status:  new => closed
 * resolution:   => duplicate
 * milestone:  4.6 =>


Comment:

 '''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  [comment:ticket:37364:5 rmccue]:
 > It'd be nice if Requests didn't trigger a warning, but the usage is
 incorrect here.

 Closing as duplicate of #37364.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/37618#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list