我正在尝试在我的 d2l orgUnit 中创建内容,但我不断收到 404 Page not found 。我从 Android 模拟器调用它。我已经使用 POST API 成功创建了一个模块和一个主题链接。我确实看过这篇文章404 Posting Content to Desire2Learn,它帮助我使模块和链接正常工作,但我只是无法将上传文件作为主题工作。我怀疑它可能是 URL,因为我不确定要放什么,所以我放了一个我在组织单元中创建的相对路径。帖子404 Posting Content to Desire2Learn提到使用“在组织单位的现有内容空间内的有效位置 URL”。我还尝试将 /content/enforced/... 文件夹作为 URL 无济于事。我不确定这是问题所在,还是红鲱鱼......
这是我的代码:
String body = "--xxBoundaryxx " +
"Content-Type: application/json " +
"{" +
"\"Title\": \"Testing an upload\"," +
"\"ShortTitle\": \"test\"," +
"\"Type\": 1," +
"\"TopicType\": 1," +
"\"URL\": \"/test/\"," +
"\"StartDate\": null," +
"\"EndDate\": null," +
"\"IsHidden\": false," +
"\"IsLocked\": false" +
" } " +
"--xxBoundaryxx " +
"Content-Disposition: form-data; name=\"file 0\"; filename=\"test.txt\" " +
"Content-Type: text/plain " +
"This is my sample file to try it out.";
URI uri = userContext.createAuthenticatedUri("/d2l/api/le/1.1/{OrgID}/content/modules/{ModuleID}/structure/", "Post");
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost post = new HttpPost(uri);
post.addHeader("Content-Type", "multipart/mixed; boundary=xxBoundaryxx");
post.setEntity(new StringEntity(body));
HttpResponse response = httpClient.execute(post);
Log.i(TAG, "Statusline: " + response.getStatusLine());
这是生成的正文(我也将 \r\n 用于换行符,但它没有帮助)。
--xxBoundaryxx
Content-Type: application/json
{
"Title": "Testing an upload",
"ShortTitle": "test",
"Type": 1,
"TopicType": 1,
"URL": "/test/",
"StartDate": null,
"EndDate": null,
"IsHidden": false,
"IsLocked": false
}
--xxBoundaryxx
Content-Disposition: form-data; name="file 0"; filename="test.txt"
Content-Type: text/plain
This is my sample file to try it out.
到底是怎么回事?getStatusLine 总是返回 404 错误...我知道这不是权限问题,因为我可以使用非常相似的代码成功创建模块和链接主题。非常感谢任何指导。