Click here to Skip to main content
15,868,016 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 = "http://203.212.70.200/smpp/sendsms?username=someusername&password=somepassword&to=" + 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";
            try
            {
                myWriter = new StreamWriter(objRequest.GetRequestStream());
                myWriter.Write(url);
                //InsertOTPinDB();
            }
            catch (Exception eX)
            {
                //lblMsg.Text = eX.Message;
            }
            finally
            {
                myWriter.Close();
            }
            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
                sr.Close();
            }
        }
Posted
Updated 29-Jan-21 21:40pm
Comments
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
 
Comments
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