I have hosted a wordpress site on my localhost on a certain port number. Lets call that port number xxxx. When I open my browser and type
http://localhost:xxxx
I am able to reach the main home page of my wordpress site and I can see my posts over there.
So clearly its working.
Now in my react app, I am using axios.get to connect to that page and attempt to get the posts in JSON format.
So I’m typing in:
axios.get(‘http://localhost:xxxx/index.php/wp-json’).then(res=>{console.log(res)}).catch(err=>{console.log(err)})
I am getting a ” AxisError Network Error “.
But the interesting thing is, when I try another local file path URL, I instead get a ” 404 not found error “.
What could be causing this? Why is my react app not able to connect to localhost:xxxx? Is there something wrong with my url?
[ad_2]
What is the first line of response from running `curl -I` [`http://localhost`](http://localhost)`:xxxx/index.php/wp-json`? Also, did you enable pretty permalinks?
I don’t think [http://localhost](http://localhost):xxxx/index.php/wp-json is valid.
WP urls are [http://localhost](http://localhost):xxxx/wp-json – i.e. no index.php. You can remove the index.php by creating an htaccess file, which you can generate by going to Settings > Permalinks.