Prefacing this by saying that I am definitely new to Wordpress, so there may be some sort of configuration that I do not know of causing this (I am hoping it is this simple of a fix)
Recently I've taken over a decently sized Wordpress environment and am working on getting up to speed with all the quirks that come with Wordpress.
For testing purposes, what I have done is alter my hosts file to redirect all requests to my production environment, to hit local instead so that I can test local changes I've made to an endpoint that is currently running in production.
example:
127.0.0.1 api.mywebsite.com
So when testing a piece of code that calls this endpoint I have updated, I am expecting it to reroute to the local version.
The issue is that even with this host file change, for some reason I am always getting back the current version of the endpoint (the one in prod right now) and getting back what is effectively the "old" response from the endpoint.
It get's stranger though when in my code I manually change it to specifically hit localhost:
$data = wp_remote_get('http://localhost/site/data.json');
print_r($data);
(I have also tried specifically 127.0.0.1)
The output from this print statement only gives me back the headers of the response, and then the "Body" is completely empty.
This is very strange though because if I just run a cURL to the route, or just hitting it in a browser locally I am able to get the valid response back every single time, so it is definitely not an issue with the logic of the code being run in the endpoint itself.
I have tried changing the way in which I am running the GET to that endpoint, by using the code below, but the exact same situation occurs, so it does not seem like it is a problem with the way in which I am trying to call this endpoint.
$apiRequest = new WP_Http;
$data = $apiRequest->request(
'http://localhost/site/data.json',
array('decompress' => false)
);
Does anyone know if there are some sort of Wordpress project settings that could be causing this? Such as overriding my hosts file change that redirect all prod traffic to local?
I have never run into a situation like this before, and my attempts at debugging it thus far have been completely useless.
Just to reiterate my situation here, what I am trying to do is be able to test the local changes I've made to an production endpoint by hitting the prod environment and having my hosts file redirect me to the local version, but it seems like my Wordpress configuration (or something else) is always trying to re route me back to what the current prod version of the endpoint is, thus getting a response that is not updated.
Then if I try to specifically tell in my code to hit the local version of the endpoint, I am getting back NO response in the "body" at all. (example below):
Array ( [headers] => Requests_Utility_CaseInsensitiveDictionary Object ( [data:protected] => Array ( [server] => nginx/1.10.2 [date] => Fri, 17 Mar 2017 17:31:37 GMT [content-type] => text/html; charset=UTF-8 [x-powered-by] => PHP/5.5.9-1ubuntu4.20 [set-cookie] => Array ( [0] => PHPSESSID=f42o8ubvk0ohr2mfjogmvmm5p4; path=/ [1] => wfvt_3956933299=58cc1d7825ee1; expires=Fri, 17-Mar-2017 18:01:36 GMT; Max-Age=1800; path=/; httponly ) [pragma] => no-cache [expires] => Wed, 11 Jan 1984 05:00:00 GMT [cache-control] => no-cache, must-revalidate, max-age=0 [link] => ; rel="https://api.w.org/" [content-encoding] => gzip ) ) [body] =>
Any help is greatly appreciated!