0
是否有可能从外部服务器发送POST请求到Moodle,然后,已经在Moodle中,使用数据做一些操作并保存到数据库(由本地插件创建的数据库表)。 有没有可能做到这一点? 谢谢大家的帮助。发送请求与外部服务器的数据到Moodle
是否有可能从外部服务器发送POST请求到Moodle,然后,已经在Moodle中,使用数据做一些操作并保存到数据库(由本地插件创建的数据库表)。 有没有可能做到这一点? 谢谢大家的帮助。发送请求与外部服务器的数据到Moodle
您可以使用Web服务
https://docs.moodle.org/dev/Web_services
这里有一些简短的说明
/admin/search.php?query=enablewebservices
/admin/settings.php?section=webserviceprotocols
/admin/settings.php?section=externalservices
/admin/roles/manage.php
webservice/rest:use
php
为用户创建一个令牌/admin/settings.php?section=webservicetokens
然后,你可以做这样的事情:
$tokenurl = 'http://[url]/login/token.php?username=xxx&password=xxx&service=yourserviceshortname';
$tokenresponse = file_get_contents($tokenurl->out(false));
$tokenobject = json_decode($tokenresponse);
if (!empty($tokenobject->error)) {
echo $tokenobject->error;
die();
}
$functionurl = 'http://[url]/webservice/rest/server.php';
$functionurl .= '?wstoken=' . $tokenobject->token;
$functionurl .= '&wsfunction=functionname';
$functionurl .= '&moodlewsrestformat=json';
$functionurl .= '¶m1=xxx';
$functionurl .= '¶m2=yyy';
$functionresponse = file_get_contents($functionurl);
$object = json_decode($functionresponse);
var_dump($object);
有关可用功能的完整列表,请参阅/admin/webservice/documentation.php
非常感谢您的帮助 –
你应该问一个更具体的问题表明你做了一些努力来首先自己寻找答案:[我如何问一个好问题?](http://stackoverflow.com/help/how-to-ask) –
实际上我不知道任何可能做到这一点......我知道如何从Moodle发送数据到外部服务器,但如何从外部服务器到Moodle ... –