无法使用Jive REST API发布共享 - 获得400 Bad Request错误

时间:2014-06-17 15:12:42

标签: c# json rest jive

我正在尝试使用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>>"

}

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

0 个答案:

没有答案