Ehsan Akbar
Ehsan Akbar

Reputation: 7281

send a request to wbservice without redirect in asp.net

I am using a url to send sms in my website as you can see here :

http://37.130.202.188/class/sms/webservice/send_url.php?from=50005150149148&to=09120838238&msg=Hi&uname=*****&pass=****

But i need to send my request to send the sms without redirect .how can i do that?I used response.redirect but it caused to redirect .!!!

I don't need any redirect in my website because after sending the sms i do other operations.

i am using c# -asp.net Best regards

Upvotes: 0

Views: 2225

Answers (1)

Vishal Suthar
Vishal Suthar

Reputation: 17193

Here you go:

1) Using WebClient:

String response = new System.Net.WebClient().DownloadString(YOUR_URL);

2) Using HttpWebRequest:

string _url = "http://37.130.202.188/class/sms/webservice/send_url.php?from=50005150149148&to=09120838238&msg=Hi&uname=*****&pass=****";

string _respose = GetResponse(_url);

public string GetResponse(string sURL)
{
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(sURL); request.MaximumAutomaticRedirections = 4;
    request.Credentials = CredentialCache.DefaultCredentials;
    try
    {
        HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream receiveStream = response.GetResponseStream();
        StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8); string sResponse = readStream.ReadToEnd();
        response.Close();
        readStream.Close();
        return sResponse;
    }
    catch
    {
        lblMsg.Text = "There might be an Internet connection issue..";
        return "";
    }
}

Upvotes: 2

Related Questions