WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#37888 closed defect (bug) (duplicate)

wp_remote_get() problems after upgrade to 4.6

Reported by: differentthemes Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.6
Component: HTTP API Keywords:
Focuses: Cc:

Description

Just upgraded my WordPress from 4.5.3 to 4.6 and

wp_remote_get('http://www.geoplugin.net/json.gp?ip=8.8.8.8');

stopped working, the response I get is

Array
(
    [headers] => Requests_Utility_CaseInsensitiveDictionary Object
        (
            [data:protected] => Array
                (
                    [date] => Tue, 30 Aug 2016 16:45:15 GMT
                    [content-type] => text/html; charset=iso-8859-1
                    [content-length] => 209
                    [server] => Apache
                )

        )

    [body] => Forbidden

You don't have permission to access /json.gp
on this server.
    [response] => Array
        (
            [code] => 403
            [message] => Forbidden
        )

    [cookies] => Array
        (
        )

    [filename] => 
    [http_response] => WP_HTTP_Requests_Response Object
        (
            [response:protected] => Requests_Response Object
                (
                    [body] => Forbidden

You don't have permission to access /json.gp
on this server.
                    [raw] => HTTP/1.1 403 Forbidden
Date: Tue, 30 Aug 2016 16:45:15 GMT
Content-Type: text/html; charset=iso-8859-1
Content-Length: 209
Connection: close
Server: Apache

Forbidden

You don't have permission to access /json.gp
on this server.
                    [headers] => Requests_Response_Headers Object
                        (
                            [data:protected] => Array
                                (
                                    [date] => Array
                                        (
                                            [0] => Tue, 30 Aug 2016 16:45:15 GMT
                                        )

                                    [content-type] => Array
                                        (
                                            [0] => text/html; charset=iso-8859-1
                                        )

                                    [content-length] => Array
                                        (
                                            [0] => 209
                                        )

                                    [server] => Array
                                        (
                                            [0] => Apache
                                        )

                                )

                        )

                    [status_code] => 403
                    [protocol_version] => 1.1
                    [success] => 
                    [redirects] => 0
                    [url] => http://www.geoplugin.net/json.gp?ip=8.8.8.8
                    [history] => Array
                        (
                        )

                    [cookies] => Requests_Cookie_Jar Object
                        (
                            [cookies:protected] => Array
                                (
                                )

                        )

                )

            [filename:protected] => 
            [data] => 
            [headers] => 
            [status] => 
        )

)

In case I replace the

wp_remote_get('http://www.geoplugin.net/json.gp?ip=8.8.8.8');

with

file_get_contents('http://www.geoplugin.net/json.gp?ip=8.8.8.8');

All works fine, also if I run the

wp_remote_get('http://www.geoplugin.net/json.gp?ip=8.8.8.8');

on WP 4.5.3 or older, all works fine.

What has changed?? Am I missing something or is this a bug?

Change History (1)

#1 @jeremyfelt
4 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Hi @differentthemes, thanks for the ticket. I was able to reproduce the same issue using the provided URL. After investigating, it looks like this is a duplicate of #37820, which points out a change in how CURLOPT_REFERER is set. If I manually set that, the request works as expected.

I'm going to close this out as a duplicate. Please keep an eye on that ticket for patches to test and leave feedback there.

Note: See TracTickets for help on using tickets.