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

本文关键字:wbservice 请求 重定向 asp net | 更新日期: 2023-09-27 18:05:20

我正在使用url在我的网站发送短信,你可以在这里看到:

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

但我需要发送我的请求发送短信没有重定向。我怎么能做到这一点?我用的是response.redirect,但是它导致了重定向!!

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

我使用c# -asp.net最好的祝福

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

给你:

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 "";
    }
}