0

我正在尝试使用 REST API(使用 C#)在 VersionOne 中创建一个计划。根据他们的“创建新资产”页面,我发出了获取 XML 的请求,设置了 2 个属性(TimeboxLength 和 TimeboxGap)并将其发回。响应结束为远程服务器返回错误:(404)未找到。

我尝试在基本 url 和范围级 url 上创建它,而不是快乐。

我的代码如下所示:

request = WebRequest.Create(string.Format("{0}/rest-1.v1/Data/",url)) as HttpWebRequest;
request.Credentials = System.Net.CredentialCache.DefaultCredentials;
request.Method = "POST";
request.ContentType="application/xml";
using (StreamWriter rs = new StreamWriter(request.GetRequestStream()))
{
    //This string is the populated xml skeleton retrieved from the website 
    string schedule = string.Concat("<?xml version='1.0' encoding=\"UTF-8\"?>",
        "<Asset href=\"/WUP/rest-1.v1/New/Schedule\">",
        "   <Attribute name=\"TimeboxLength\" act=\"set\">42 Days</Attribute>",
        "   <Attribute name=\"TimeboxGap\" act=\"set\">2 Days</Attribute>",
        "</Asset>");
    rs.Write(schedule);
    rs.Flush();
    rs.Close();
}
try
{
    response = request.GetResponse() as HttpWebResponse;
}
catch (WebException we)
{
    System.Diagnostics.Debug.WriteLine(we.Status.ToString());
}

我不认为这是一个 oauth 问题,现在只使用凭证缓存就可以了。谁能指出我做错了什么?

提前致谢。

4

1 回答 1

0

编辑刚刚注意到你说 404 所以这可能是路径。确保它的 /rest-1.v1/Data/Schedule - 并且案例很重要!

你是如此接近。首先,如果你检查 meta(所有真相的守护者),默认情况下,你需要 3 样东西。在这里找到...

V1instance/meta.v1/Schedule?xsl=api.xsl

所以只需在你的有效载荷中添加这样的东西

string schedule = string.Concat("<?xml version='1.0' encoding=\"UTF-8\"?>",
        "<Asset>",
  --->  "   <Attribute name=\"Name\" act=\"set\">Password Reset Schedule</Attribute>",
        "   <Attribute name=\"TimeboxLength\" act=\"set\">42 Days</Attribute>",
        "   <Attribute name=\"TimeboxGap\" act=\"set\">2 Days</Attribute>",
        "</Asset>");

你应该很高兴。此外,不需要资产元素中的 href,如果需要,它会在请求中返回(当有很多东西返回时很有用)

于 2015-09-18T12:11:46.217 回答