我目前正在开发一个使用 REST 接口连接到共享点站点的 Windows 8(Windows 应用商店)应用程序。目前,我已经成功地从 _vti_bin/ListData.svc/ uri 中下拉列表数据。但是,我坚持从应用程序内创建新的列表项,并将这些项发布回共享点。
我正在尝试使用 HTTP POST 方法,但是收到 405 错误代码:MethodNotAllowed。下面是我的代码:
HttpClientHandler clientHandler = new HttpClientHandler();
clientHandler.UseDefaultCredentials = true;
HttpClient newClient = new HttpClient(clientHandler);
// HttpResponseMessage response = newClient.PostAsync("http://sharepoint/.../_vti_bin/ListData.svc/Nominations", test);
var resp = await newClient.GetAsync(newUri("http://sharepoint/.../_vti_bin/ListData.svc/Nominations"));
using (newClient)
using (var ms = new MemoryStream())
{
var djs = new DataContractJsonSerializer(typeof(NominationsItem));
djs.WriteObject(ms, test);
ms.Position = 0;
var sc = new StreamContent(ms);
sc.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
resp = test == null
? await newClient.PutAsync(new Uri("http://sharepoint/.../_vti_bin/ListData.svc/Nominations"), sc)
: await newClient.PostAsync(new Uri("http://sharepoint.../_vti_bin/ListData.svc/Nominations"), sc);
resp.EnsureSuccessStatusCode();
}
任何帮助,将不胜感激!