我很好奇是否有人使用Valance在Java中成功实现了D2L中的路由,如下所示:
PUT / d2l / api / le /(D2LVERSION:version)/(D2LID:orgUnitId)/ grades /(D2LID:gradeObjectId)/ values /(D2LID:userId)
当我彻底检查所需的ID与D2L中的记录相匹配时,我一直在努力接收来自此呼叫的404。当我使用Java中使用的讲师级别帐户登录D2L时,我看到课程,测试和参与者都在那里。这些ID在Java代码中用于调用上述路由,但我收到404并且等级未更新。
以下是代码片段:
HttpURLConnection connection = null ;
try {
uri = userContext.createAuthenticatedUri ("/d2l/api/le/1.0/"+courseId+"/grades/"+gradeId+"/values/"+ userId, "PUT");
connection= (HttpURLConnection)uri.toURL().openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("PUT");
connection.setRequestProperty("Content-Type", "application/json");
OutputStream os = connection.getOutputStream();
String updatedScore = "{\"GradeObjectType\":1,\"PointsNumerator\":\"5\"}";
os.write(updatedScore.getBytes());
os.flush();
}catch(Exception e){
e.printStackTrace();
}
正在传递courseID,gradeID和userID,并且已在D2L Web UI中验证。 如您所见,我为GradeObjectType为1和PointsNumerator为5创建了一个JSON字符串。此教师帐户必须具有超出默认教师帐户权限的特殊权限才能允许此类调用吗?
任何想法都将不胜感激。 感谢
答案 0 :(得分:0)
更新
成功请求和响应的示例如下:也许您可以识别差异:
REQUEST:
PUT https://valence.desire2learn.com/d2l/api/le/1.0/7574/grades/4852/values/3902?x_b=xDaPHeptaw9syoI1EGdeJ1&x_a=L2Hd9WvDTcyiyu5n2AEgpg&x_d=6U5NTYnTswz4gnu-vZHT3bajswsp3jvxYtwzoeOWKUs&x_c=a6f5hEMrvAxC6PS5UlSUOusVpj-XKnOBwxqhYg5pNtg&x_t=1343070852 HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: application/json
{
"GradeObjectType": 1,
"PointsNumerator": 9
}
RESPONSE:
HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 0
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Date: Mon, 23 Jul 2012 19:14:48 GMT