在asp.net中向wbservice发送请求而不重定向

时间:2015-07-29 07:03:35

标签: c# asp.net web-services redirect

我正在使用网址在我的网站上发送短信,如您所见:

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

但是我需要发送我的请求来发送没有重定向的短信。我可以这样做吗?我使用response.redirect但它导致重定向。!!!

我的网站不需要任何重定向,因为在发送短信后我会做其他操作。

我正在使用c#-asp.net 最好的问候

1 个答案:

答案 0 :(得分:2)

你走了:

1)使用WebClient

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

2)使用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 "";
    }
}