从 .Net 控制台应用程序访问 Moodle API
Access Moodle API from .Net Console Application
对于我的一个项目,我需要管理 Moodle 的一些属性,包括(但可能不限于)Creating/Updating 用户和管理注册。
我需要在 .Net (4.0+) 控制台应用程序中创建此界面,以便可以从其他系统处理信息。
我已经检查了 NuGet 的 Moodle 程序包,但我找不到任何东西。
你能告诉我如何实现这个界面吗?
提前致谢。
我认为没有可用的包装器。您将需要启用 moodle 网络服务:
https://docs.moodle.org/dev/Web_services
并创建你自己的。我为此使用 RestSharp:
此代码可用于访问课程信息
string result = "";
string methodName = "GetCourse";
string apiName = "core_course_get_courses";
string apiCall = moodleUrl + "?wstoken=" + token + "&wsfunction=" + apiName + "&moodlewsrestformat=json";
try
{
using (WebClient client = new WebClient())
{
client.BaseAddress = apiCall;
client.Headers[HttpRequestHeader.Accept] = "application/json";
result = client.DownloadString(apiCall);
对于我的一个项目,我需要管理 Moodle 的一些属性,包括(但可能不限于)Creating/Updating 用户和管理注册。
我需要在 .Net (4.0+) 控制台应用程序中创建此界面,以便可以从其他系统处理信息。
我已经检查了 NuGet 的 Moodle 程序包,但我找不到任何东西。
你能告诉我如何实现这个界面吗?
提前致谢。
我认为没有可用的包装器。您将需要启用 moodle 网络服务:
https://docs.moodle.org/dev/Web_services
并创建你自己的。我为此使用 RestSharp:
此代码可用于访问课程信息
string result = "";
string methodName = "GetCourse";
string apiName = "core_course_get_courses";
string apiCall = moodleUrl + "?wstoken=" + token + "&wsfunction=" + apiName + "&moodlewsrestformat=json";
try
{
using (WebClient client = new WebClient())
{
client.BaseAddress = apiCall;
client.Headers[HttpRequestHeader.Accept] = "application/json";
result = client.DownloadString(apiCall);