我目前正在开发使用REST界面连接到sharepoint站点的Windows 8(Windows应用商店)应用。目前,我已成功设法从_vti_bin / ListData.svc / uri下拉列表数据。但是,我坚持在应用程序中创建新的列表项,并将这些列表发布回sharepoint。
我正在尝试使用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();
}
任何帮助将不胜感激!