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的主要内容,如果未能解决你的问题,请参考以下文章