Title: Problem with HTTP API
Last modified: May 5, 2019

---

# Problem with HTTP API

 *  Resolved [salvatorericcardi](https://wordpress.org/support/users/richdeveloper/)
 * (@richdeveloper)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/problem-with-http-api/)
 * Hi,
    I’ve a problem with the WordPress API in the subject. I posted the code 
   below: this returns blank page, instead it should return an HTTP Response or 
   a WP_Error, but nothing. Why?
 *     ```
       <?php
   
       class The_Crawler {
   
           public function __construct() { }
   
           public function get_classifieds( $urls ) {
   
               foreach($urls as $url) {
   
                   $response = wp_remote_get( $url );
   
                   print_r($response);
   
                   if ( is_array( $response ) && ! is_wp_error( $response ) ) {
                       $body = wp_remote_retrieve_body( $response ); 
   
                       $pattern = '<h3\sclass="title">.*</h3>';
                       preg_match( $pattern, $body, $titles );
                       print_r( $titles );
                   }
   
               }
   
           }
   
       }
   
       $urls = [
           'https://www.kijiji.it/motori/moto-e-scooter/'
       ];
   
       The_Crawler::get_classifieds( $urls );
       ```
   
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fproblem-with-http-api%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [Joy](https://wordpress.org/support/users/joyously/)
 * (@joyously)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/problem-with-http-api/#post-11498085)
 * Do you actually create an instance of the class?
    Turn on debug and log the errors
   in a file. [https://codex.wordpress.org/Editing_wp-config.php#Debug](https://codex.wordpress.org/Editing_wp-config.php#Debug)
   Look at the error log to see what is happening.
 *  Thread Starter [salvatorericcardi](https://wordpress.org/support/users/richdeveloper/)
 * (@richdeveloper)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/problem-with-http-api/#post-11498204)
 * Call to undefined function wp_remote_get(). I loaded WordPress: why do I receive
   this error?
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/problem-with-http-api/#post-11498292)
 * It looks like you’re calling `The_Crawler::get_classifieds()` directly from your
   plugin code page. When plugins are loaded and when this call occurs, WP is not
   yet stable. You need to make such a call as part of an action callback for an
   action like “init” or later.
 *  Thread Starter [salvatorericcardi](https://wordpress.org/support/users/richdeveloper/)
 * (@richdeveloper)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/problem-with-http-api/#post-11498295)
 * Ok thanks. I solved with the PHP method file_get_contents().

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Problem with HTTP API’ is closed to new replies.

## Tags

 * [http api](https://wordpress.org/support/topic-tag/http-api/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 4 replies
 * 3 participants
 * Last reply from: [salvatorericcardi](https://wordpress.org/support/users/richdeveloper/)
 * Last activity: [6 years, 11 months ago](https://wordpress.org/support/topic/problem-with-http-api/#post-11498295)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
