Click here to Skip to main content
15,612,584 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have used this code to send sms . But even though the provider says there are enough cridets left it shows an error
Authorization failed for sendsms

What I have tried:

<pre>private void SendSMS(string randomNumber, string Phone)
            var SmsText = "Your OTP for Hearing test is " + randomNumber;
            Phone = "+91" + Phone;
            String url = "" + Phone + "&from=BEHEAR&udh=0&text=" + SmsText;
            StreamWriter myWriter = null;
            HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url);

            objRequest.Method = "POST";
            objRequest.ContentLength = Encoding.UTF8.GetByteCount(url);
            objRequest.ContentType = "application/x-www-form-urlencoded";
                myWriter = new StreamWriter(objRequest.GetRequestStream());
            catch (Exception eX)
                //lblMsg.Text = eX.Message;
            HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
            using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
                var result = sr.ReadToEnd();
                lblError.Text = result;
                //ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('" + result + "')", true);
                // Close and clean up the StreamReader
Updated 29-Jan-21 21:40pm
Dave Kreskowiak 30-Jan-21 12:40pm    
The only people who are going to be able to help you are the people who own the API you're trying to connect to.

Who owns this SMS api? It's clear that the API needs authorization as part of security and you are missing on it.

Talk to the API owner and pass the authorization related information as part of hour request. Most of the times they are tokens passed as request headers.
Share this answer
I have talked with the service provider . they are say we still have enough credit left. Last time I encountered the same problem was because the credits have finished , but this time they are saying cridets are there.
Share this answer
Richard MacCutchan 30-Jan-21 6:36am    
Did you think to ask them why the authorisation failed? After all, it is their system so they should be able to tell you.

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