API无法向移动设备发送短信

时间:2014-11-21 17:35:24

标签: asp.net-mvc c#-4.0

我在使用此api向移动设备发送短信时遇到问题,我收到确认消息已成功发送。但实际上它会扣除消息余额并显示交付失败。

static string sUserID = "Admin";
static string sPwd = "Admin@123";          
static string fromaddress = "Company Name";
static string ToAddress = "9999999999";
static string sMessage = "Test SMS From xyz person";

public ActionResult SMS()
{
    string sURL = "http://www.metamorphsystems.com/index.php/api/bulk-sms?username=" + sUserID + "&password=" + sPwd + "&from=" + fromaddress + "&to=" + ToAddress + "&message=" + sMessage + "&sms_type=" + 2 + "&filter_dnd=" + 1;
    string sResponse = GetResponse(sURL);
    Response.Write(sResponse);
    return View();
}

public static string GetResponse(string sURL)
{
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(sURL);
    request.MaximumAutomaticRedirections = 4;
    CredentialCache.DefaultNetworkCredentials.UserName = sUserID;
    CredentialCache.DefaultNetworkCredentials.Password = sPwd;
    CredentialCache.DefaultNetworkCredentials.Domain = "http://www.metamorphsystems.com";
    request.Credentials = CredentialCache.DefaultNetworkCredentials;
    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
    {
        return "";
    }
}

0 个答案:

没有答案