如何使用web api从C#windows表单应用程序发送短信 [英] How to send sms from C# windows form application using web api
本文介绍了如何使用web api从C#windows表单应用程序发送短信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个c#windows表单应用程序,因为我有一个用于将短信发送给客户端的表单。要发送短信,我尝试了以下代码,但它显示消息失败。我不知道该怎么办。请纠正我,帮帮我。
我尝试过:
Hi, I am working on a c# windows form application, in that I have one form which is used to send the sms to the clients. To send sms I tried the below code but it is showing message failed. I don't know what to do. please correct me, help me.
What I have tried:
if (txtMobile.Text == string.Empty)
{
MessageBox.Show("Enter Valid Mobile No");
}
else
{
using (System.Net.WebClient client = new System.Net.WebClient())
{
try
{
string url = "http://bulksms.abc.in/API/WebSMS/Http/v1.0a/index.php? " +
"&username=" + System.Web.HttpUtility.UrlEncode(txtUserName.Text) +
"&password=" + System.Web.HttpUtility.UrlEncode(txtPassword.Text) +
"&sender=" + txtSenderID.Text +
"&to=" + txtMobile.Text +
"&message=" + System.Web.HttpUtility.UrlEncode(txtSmsContent.Text, System.Text.Encoding.GetEncoding("ISO-8859-1"));
string result = client.DownloadString(url);
if (result.Contains("OK"))
MessageBox.Show("Your message has been successfully sent.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
else
MessageBox.Show("Message Failed", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception exr)
{
MessageBox.Show(exr.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
推荐答案
您的代码是发送一些东西到php文件。你必须联系那些构建该文件的人,以便更好地理解它失败的原因。我们无法知道。
Your code is sending something to a php file. You have to contact whoever built that file to get a better understanding of why it failed. There is no way for us to know.
这篇关于如何使用web api从C#windows表单应用程序发送短信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文