csharp REST呼叫C#承载令牌POST

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp REST呼叫C#承载令牌POST相关的知识,希望对你有一定的参考价值。

//make request body
dynamic packet = mkPacket(parameters);
string ActivityId = "";
var client = new RestClient(endpoint + "/apiEndPoint");
RestRequest request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer " + token);
request.AddHeader("Content-Type", "application/json");
//post request body
request.AddParameter("undefined", packet, ParameterType.RequestBody);
request.Timeout = 5000;
IRestResponse response = client.Execute(request);
if (response.IsSuccessful)
{
    try
    {
      //parse the response object
        dynamic obj = JObject.Parse(response.Content);
    }
    catch (Exception ex)
    {
        ActivityId = ex.GetBaseException().ToString();
        log.Error($"Error writing to iMIS - Parsing Content -{ex.GetBaseException().ToString()}");
        throw ex;
    }
}
else
{
    ActivityId = response.Content.ToString();
    log.Error($"Error writing to iMIS - Response unsuccessful");
    throw new Exception("Error in method - writing Activity");
}

以上是关于csharp REST呼叫C#承载令牌POST的主要内容,如果未能解决你的问题,请参考以下文章

如何使用 Rest Assured 从 KeyCloak 服务获取承载令牌

使用 Azure AD 承载令牌时身份验证失败,返回容器列表 [Azure Blob] [Azure AD OAuth 2.0] [REST API]

如何将接收到的(承载)访问令牌传递给生成的 REST 客户端,以调用安全的 API-Gateway 端点

使用承载令牌在 C# 中构建 post HttpClient 请求

HttpClient中的授权承载令牌?

我如何从 HttpClient 获取承载令牌?