Sorry, you need to enable JavaScript to visit this website.

You are here

C# RestSharp Incompatiability

1 post / 0 new

Lee's picture
by Lee

C# RestSharp Incompatiability

I am trying to use the C# RestSharp functions which (using PostMan and other tools relies on Version 105.1.0

However, this version has been depreciated and has been replaced by a new version due to security notices.

Running the new framework, results in an invalid JSON code.

Can this be looked into please.

Code:

namespace TestAppX48
{
{
    internal class Program
    {
        static void Main(string[] args)
        {
            var client = new RestClient(https://tapi.telstra.com/v2);
            var request = new RestRequest("oauth/token", Method.Post);
            request002EAddHeader("Content-Type", "application/x-www-form-urlencoded");
            request.AddParameter("client_id", "xxxxxxxxxxxxxxxxxxxxxxxxxx");
            request.AddParameter("client_secret", "xxxxxxxxxxxx");
            request.AddParameter("grant_type", "client_credentials");
            request.AddParameter("scope", "");
            Task<RestResponse> response = client.ExecuteAsync(request);
            response.Wait();
            Console.WriteLine(response.Result.Content);

            var requestSend = new RestRequest("messages/sms", Method.Post);
            requestSend002EAddHeader("Accept", "application/json");
            requestSend002EAddHeader("Content-Type", "application/json");
            requestSend002EAddHeader("Authorization", $"Bearer xxxxxxxxxxxxxxxxx");
            var body = @"{
" + "\n" +
            @"    ""to"": ""+61xxxxxxxx"",
" + "\n" +
            @"    ""validity"": ""60"",
" + "\n" +
            @"    ""priority"": false,
" + "\n" +
            @"    ""notifyURL"": "http://YOUR_URL/",
" + "\n" +
            @"    ""body"": ""Message text goes here""
" + "\n" +
            @"}";
            requestSend.AddParameter("application/json", body, ParameterType.RequestBody);
            Task<RestResponse> responseSend = client.ExecuteAsync(requestSend);
            responseSend.Wait();
            Console.WriteLine(responseSend.Result.Content);
        }
    }
}

Results:
              {
                "status":"400",
                "code":"INVALID-JSON-FORMAT",
                "message":"Refer to API docs at https://dev.telstra.com"
              }