c# - 无法使用 Jive REST API 发布共享 - 出现 400 Bad Request 错误

标签 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>>"

}

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

最佳答案

我自己弄明白了,我收到错误是因为我将无效的 URI 对象传递给共享 REST 端点的共享参数。共享参数需要

形式的内容 URI

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

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

关于c# - 无法使用 Jive REST API 发布共享 - 出现 400 Bad Request 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24267442/

相关文章:

php - IOS SWIFT 2 - Http 将 json 数组发布到服务器

javascript - 如何对 AJAX 调用返回的类似数据进行分组?

javascript - 如何在 MarkLogic JSON 中搜索文件中特定路径处的键值?

c# - 将excelsheet文件中的数据导入mysql数据库C#

c# - C# 中的 "Abstract"接口(interface)

c# - IQueryable<T> 给出的结果与 List<T> 不同

c - 允许在c中共享内存的json库

c# - 在 Linux 和 Windows 中与 c# 集成的跨平台 c++

python - 合并两个复杂的 JSON 对象

rest - 尝试访问服务器上的 rest API 时出现错误 500(在开发期间正在本地主机上工作)