Click here to Skip to main content
15,910,121 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello!

I write code given below, I do not get any error but I do not get message at mobile when i debug it. The debug step jumped from first bold line to directly Catch {} block ..

can anybody help me.. what can i do to get message at mobile

protected void Page_Load(object sender, EventArgs e)
   {

   }
   public string mobile
   {
       get;
       set;
   }
   public string message
   {
       get;
       set;
   }
   public string username
   {
       get;
       set;
   }
   public string password
   {
       get;
       set;
   }
   public string domian
   {
       get;
       set;
   }
   protected void btnSend_Click(object sender, EventArgs e)
   {
       try
       {
           mobile = txtMobile.Text;
           message = txtMessage.Text;
           username = txtName.Text;
           password = txtPassword.Text;
           domian = txtDomain.Text;
           string result = apicall("http://"+ domian +"/Default.aspx?username="+username+"&password="+password+"&sender=&to="+mobile+"&message="+message);
           if (!result.StartsWith("Wrong Username or Password"))
           {
               ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "success", "alert('Message Sent')", true);
           }
           else
           {
               ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "success", "alert('Message Sending Failed')", true);
           }

       }
       catch(Exception ex)
       {
           throw ex;
       }
   }
   public string apicall(string url)
   {
      HttpWebRequest httpreq = (HttpWebRequest)WebRequest.Create(url);


       try
       {
Debugger jumps from here
   HttpWebResponse httpres = (HttpWebResponse)httpreq.GetResponse();
    StreamReader sr = new StreamReader(httpres.GetResponseStream());

    string results = sr.ReadToEnd();

    sr.Close();
    return results;



}
To here
    catch
    {
        return "0";
    }
}


Thank you in advance
Posted
Updated 16-Jul-10 1:20am
v2
Comments
Fredrik Bornander 16-Jul-10 6:51am    
How about catching Exception and then look at what exception was thrown?
narendrarathod 16-Jul-10 7:13am    
Thanks for giving me reply its thrown can have u any idea so please help me
OriginalGriff 16-Jul-10 8:05am    
"Thanks for your favorable reply i already tried it but i got error"

So what error did you get? If you don't look at it, then you don't know what the problem is!
narendrarathod 16-Jul-10 8:13am    
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.WebException: The remote server returned an error: (404) Not Found.
OriginalGriff 16-Jul-10 8:25am    
Answer updated.

1 solution

You are getting an error, but your try - catch block is hiding it. Replace the catch line with
catch(Exception ex)
and examine the error message given in the exception object ex - it should tell you what is happening.

BTW: I modified your question to make it more readable - have a look and do the same yourself in future!

"The remote server returned an error: (404) Not Found"
That means that your url is wrong. The remote website is saying "I do not have a page that matches your address".
Check:
1) Modify apicall to print out exactly what the HttpWebRequest is going to connect to.
2) Copy this string into the address bar of a normal web browser.
3) Try to connect to the page manually.
4) Edit your address until you get the connection ok.
5) Modify your code so it uses that URL instead of the current one.
 
Share this answer
 
v2
Comments
narendrarathod 16-Jul-10 7:55am    
Thanks for your favorable reply i already tried it but i got error

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