Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to use Web Api to send sms from my website
and use this code but not work probably.


C#
string Username ="My username";
    string Password ="My password";
    string TO ="mobile number";
    string TEXT = "some text";
    string sURL;
    StreamReader objReader;
    sURL = "http://ars-sms.ir/API/SendSMS.asmx?Username='" + Username + "@Password=" + Password + "@TO" + TO + "@TEXT" + TEXT;
    WebRequest wrGETURL;
    wrGETURL = WebRequest.Create(sURL);
    try
    {
        Stream objStream;
        objStream = wrGETURL.GetResponse().GetResponseStream();
        objReader = new StreamReader(objStream);
        objReader.Close();
    }
    catch (Exception ex)
    {
        ex.ToString();
    }

Is there any problem with my code?
Posted
Comments
ZurdoDev 8-Jan-14 14:14pm    
What does happen?
m-e-h-d-h-i 8-Jan-14 14:17pm    
nothing
ZurdoDev 8-Jan-14 14:21pm    
Did you put a breakpoint and walk through it? Because if there is an error in your try you'll never know just by running it.
m-e-h-d-h-i 8-Jan-14 14:25pm    
I try in several time but nothing happend.
ZurdoDev 8-Jan-14 14:30pm    
You haven't answered my question. Did you debug it?

1 solution

Are you sure the below line is correct?
C#
sURL = "http://ars-sms.ir/API/SendSMS.asmx?Username='" + Username + "@Password=" + Password + "@TO" + TO + "@TEXT" + TEXT;

1. Can you call the service using HTTP GET?
2. Why do you have a single quote before the Username variable? Is this really needed?
3. Why are you using the @ character to separate your parameters? Is this required by the ars-sms.ir site? Normally you would use the & character.
4. I don't see an = character between the keyword and value for the TO and TEXT parameters.

If you don't know why or have an answer to the above questions you may want to try replacing your URL with the below...
C#
sURL = "http://ars-sms.ir/API/SendSMS.asmx?Username=" + Username + "&Password=" + Password + "&TO=" + TO + "&TEXT=" + TEXT;
 
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