gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 15:54:22 24 4
gpt4 key购买 nike

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com