我正在尝试使用 REST Webservices 在 Project Server 2013 中创建一个项目,但是当我尝试向项目服务器发出 POST 请求时,我收到了 403 Forbidden Exception。基本疑问是“Project Server 是否允许执行 POST 请求?”
对于 GET 和 POST 请求以及 Project Server,端点 URL 是否保持相同
请为此提供一些输入。
代码如下:-
Guid pguid = new Guid();
string projGuid = pguid.ToString();
string projName = "Mercedes";
string startDate = DateTime.Now.ToShortDateString().ToString();
string URI = "http://ServerName/projectservername/_api/ProjectData/Projects";
//string URI = "http://ServerName/projectservername/Projects.aspx";
//string myParameters = "BaselineNumber=0&ProjectId=c34ca0f0-1acd-e211-b2e80155def232b&ProjectName=ProjName;
string myParameters = "ProjectId=" + projGuid + "&ProjectName=" + projName + "&ProjectStartDate="+ startDate;
using (WebClient wc = new WebClient())
{
wc.Credentials = new System.Net.NetworkCredential(username, password, domain);
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
wc.Headers.Add("X-HTTP-Method", "PUT");
string HtmlResult = wc.UploadString(URI, myParameters);
// WebHeaderCollection head = wc.ResponseHeaders;
Console.WriteLine(HtmlResult);
Console.WriteLine("Bye");
}