简体   繁体   中英

Sinch C# client url parse exception

I am using C# client for Sinch sms provider: Nuget Package link

Here is my code for sending sms using Sinch:

using Sinch.ServerSdk;

var smsApi = SinchFactory
                    .CreateApiFactory("my_service_plan_id", "my_secret_key")
                    .CreateSmsApi();

I am getting errors even before sending sms. Here is stack trace:

Invalid URI: The hostname could not be parsed.
   at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
   at System.Uri..ctor(String uriString)
   at Sinch.WebApiClient.WebClientRequestInterceptor`1..ctor(String baseUri, IHttpClient httpClient, IActionFilter[] filters)
   at Sinch.WebApiClient.WebApiClientFactory.CreateClient[T](String baseUri, IActionFilter[] filters)
   at Sinch.ServerSdk.ApiFactory.CreateApiClient[T](String url)
   at Sinch.ServerSdk.ApiFactory.CreateSmsApi()

Your syntax seems to be right. This works in a console application:

using System.Threading.Tasks;
using Sinch.ServerSdk;

class Program
{
    static void main(string[] args)
    {
        sendSMS().GetAwaiter().GetResult();
    }
    private static async Task sendSMS()
    {
        var smsApi = SinchFactory
                       .CreateApiFactory("mykey", "mysecretkey")
                       .CreateSmsApi();
        var sendSmsResponse = await smsApi.Sms("<mynumber>", "Hello world, this is a text message.").Send();
    }
}

and the syntax for asp.net web apps is similar. Probably your "mykey" , or "mysecretkey" is incorrect.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM