嗨我新與moodle和調用Web服務時出現錯誤。Moodle休息時間返回錯誤的功能core_user_get_users_by_field
目前我正在嘗試從moodle中檢索用戶,使用以下函數core_user_get_users_by_field,並使用rest服務來執行此操作。我已經設法創建了一個用戶,這樣我就可以使用該服務進行身份驗證。
我正在接收所述誤差是
缺少單個結構所需的關鍵:字段
波紋管是代碼用於創建一個用戶。我從錯誤中得到的問題是我需要爲帖子發送的參數格式不正確。有誰知道如何正確使用此方法或任何其他方法進行搜索。
String token = "token";
String postData = "username=username";
string createRequest = string.Format("http://domain/webservice/rest/server.php?wstoken={0}&wsfunction={1}&moodlewsrestformat=json", token, "core_user_get_users_by_field");
// Call Moodle REST Service
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(createRequest);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
// Encode the parameters as form data:
byte[] formData =
UTF8Encoding.UTF8.GetBytes(postData);
req.ContentLength = formData.Length;
// Write out the form Data to the request:
using (Stream post = req.GetRequestStream())
{
post.Write(formData, 0, formData.Length);
}
// Get the Response
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
Stream resStream = resp.GetResponseStream();
StreamReader reader = new StreamReader(resStream);
string contents = reader.ReadToEnd();
// Deserialize
JavaScriptSerializer serializer = new JavaScriptSerializer();
if (contents.Contains("exception"))
{
// Error
MoodleException moodleError = serializer.Deserialize<MoodleException>(contents);
}
else
{
// Good
}
感謝幫助很大網址 –