【问题标题】:send a request to wbservice without redirect in asp.net在 asp.net 中向 wbservice 发送请求而不重定向
【发布时间】:2015-07-29 07:03:34
【问题描述】:

我正在使用 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 最好的问候

【问题讨论】:

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


    【解决方案1】:

    给你:

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

    【讨论】:

    • 好的。更新了答案.. @EhsanAkbar
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-12
    • 2017-09-10
    相关资源
    最近更新 更多