Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want use whatsapp in my prouject but I came across an error,that I don't know what it's for:


"Newtonsoft.Json.JsonSerializationException: Error converting value 451 to type 'Twilio.Exceptions.RestException'. Path '', line 1, position 3. ---> System.ArgumentException: Could not cast or convert from System.Int64 to Twilio.Exceptions.RestException.\r\n at Newtonsoft.Json.Utilities.ConvertUtils.EnsureTypeAssignable(Object value, Type initialType, Type targetType)\r\n at Newtonsoft.Json.Utilities.ConvertUtils.ConvertOrCast(Object initialValue, CultureInfo culture, Type targetType)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType)\r\n --- End of inner exception stack trace ---\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)\r\n at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)\r\n at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)\r\n at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)\r\n at Twilio.Clients.TwilioRestClient.ProcessResponse(Response response)\r\n at Twilio.Clients.TwilioRestClient.Request(Request request)\r\n at Twilio.Rest.Api.V2010.Account.MessageResource.Create(CreateMessageOptions options, ITwilioRestClient client)\r\n at Twilio.Rest.Api.V2010.Account.MessageResource.Create(PhoneNumber to, String pathAccountSid, PhoneNumber from, String messagingServiceSid, String body, List`1 mediaUrl, Uri statusCallback, String applicationSid, Nullable`1 maxPrice, Nullable`1 provideFeedback, Nullable`1 attempt, Nullable`1 validityPeriod, Nullable`1 forceDelivery, ContentRetentionEnum contentRetention, AddressRetentionEnum addressRetention, Nullable`1 smartEncoded, List`1 persistentAction, ITwilioRestClient client)\r\n at try_for_send_inf_to_WhatsApp2.Form1.button1_Click(Object sender, EventArgs e) in D:\\Projects\\Test2\\try_for_send_inf_to_WhatsApp2\\try_for_send_inf_to_WhatsApp2\\Form1.cs:line 34"

private void button1_Click(object sender, EventArgs e)
        {
            TwilioClient.Init(
               Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID"),

              Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN")
              );
            try
            {
                var message = Twilio.Rest.Api.V2010.Account.MessageResource.Create(
                from:  new PhoneNumber("+14155238886"),
                to:new PhoneNumber("+989351091287"),
                body: "salam rezaei",
mediaUrl: new List<Uri> { new Uri("https://c1.staticflickr.com/3/2899/14341091933_1e92e62d12_b.jpg") }
//mediaUrl: new List<Uri> { new Uri("https://www.demo.twilio.com/owl.png") }
                );
            MessageBox.Show("message id:" + message.Sid);
        }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }


What I have tried:

I've used wart before, but couldn't generate a password, I've heard from some that wart is no longer supported, so I decided to use twilio
I've been trying for a while, please help me get results sooner
Posted
Updated 4-Jun-20 6:38am

1 solution

Error converting value 451 to type 'Twilio.Exceptions.RestException'
I don't know Twilio, Flickr, or any censorship you may be subject to, but HTTP Status 451 is the message returned for Unavailable For Legal Reasons

A quick search for these terms (Twilio 451) brought up this from one of their blogs
10 HTTP status codes that sound like relationship problems - Twilio[^]
451 Unavailable for legal reasons

Error code 451 comes into play when a request cannot be fulfilled because of a government mandate.
This response might not come directly from the origin server. Often legal filtering happens at the ISP level.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900