2

我正在尝试使用 C# 在.net 中使用 /Shares REST API 在 Jive 上发布共享。但是我无法执行此操作并收到以下错误:

“远程服务器返回错误:(400)错误请求。”

以下是我编写的代码:

string response = string.Empty;

using(WebClient client = new WebClient())

{

   string strJiveShareURL = "https://<JiveURL>";

          strJiveShareURL += "/api/core/v3/shares";

   var SharedJSON = new AddShareJSON

   {

      participants = new string[] {"https://<JiveURL>/api/core/v3/people/{username}" },

      shared = "https://<<Content URL to be shared>>",

      content= new Content

                {

                  type = "text/html",

                  text = "This is a test share from SharePoint to Jive"                   
                }

}; 

   var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();

   string shareJSON = serializer.Serialize(SharedJSON);

   Console.WriteLine("Setting Credentials:");

   string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes("UID:PWD"));

   client.Headers[HttpRequestHeader.Authorization]= "Basic " + credentials;

   client.Headers[HttpRequestHeader.Accept] = "application/json";

   client.Headers[HttpRequestHeader.ContentType] = "application/json";

   //BypassCertificateError();

   response = client.UploadString(strJiveShareURL, "POST", shareJSON);

   Console.WriteLine("Response:" + response);

   Console.ReadLine();



}

以下是为发布共享而创建的 JSON:

{

  "content": {

                "type":"text/html",

                "text":"This is a test share from SharePoint to Jive"

            },

           "participants": ["https://<<Jive URL>>/api/core/v3/people/<<username>>"],

           "Shared":"https://<<URL of the Content To be Shared>>"

}

如果我做错了什么,请告诉我。

4

1 回答 1

0

我自己弄清楚了这一点,我收到了错误,因为我将无效的 URI 对象传递给了 Share REST 端点的共享参数。shared 参数需要一个内容 URI,格式为

http://[[JiveURL]]/api/core/v3/contents/[[ContentID]]

早些时候我试图将 URL 传递给 Jive 导致错误的请求错误。

于 2016-04-11T12:45:15.630 回答