Use IP address to access Moodle API

Use IP address to access Moodle API

by Lucy Hong -
Number of replies: 2
I'm trying to get data via webservice API in my test ios app but I couldn't connect moodle API.
After spending long hours to find out why I've found that I need to use IP address to connect localhost API in my app. 
(https://stackoverflow.com/questions/51889837/cannot-connect-to-localhost-api-from-android-app)
But when I connect with IP address instead of the domain name, webservice functions are not working, it just redirects to the main page no matter what I call.

For example,


This should return login url but it returns the main page html tags. 
Anyone knows how to connect it via IP address or should I change the domain name as its local IP address?

Thank you for your help.
Average of ratings: -
In reply to Lucy Hong

Re: Use IP address to access Moodle API

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
What's stopping you using the URL in $CFG->wwwroot? You *have* to use that.
In reply to Howard Miller

Re: Use IP address to access Moodle API

by Lucy Hong -

Thanks for your response. 

Yes it's working after I changed $CFG->wwwroot to ip address. Thank you.