我正在使用一个for
循环,其中Webclient类Downloadstring()
方法用于加载外部 url 。Url 由 SMS 服务提供商提供,其中添加了手机号码和要传输的消息。
但是对于数组中指定的所有手机号码,消息并未提交到 SMS 网关,phNos[]
即某些号码的下载 Url 被跳过。这主要发生在数组末尾的手机号码上。
如何确保程序等待直到为特定数字加载 url,然后程序继续前进。
WebClient cli = new WebClient();
for (i=0;i<phNos.Length;i++)
{
string url = @"http://example.com?DestNo=" + phNos[i] + "&msg=" + message;
cli.DownloadString(url);
}
或者我也使用过 System.Net.HttpWebRequest
,但问题仍然存在。
for (i=0;i<phNos.Length;i++)
{
string url = @"http://example.com?DestNo=" + phNos[i] + "&msg=" + message;
Uri targetUri = new Uri(url);
HttpWebRequest hwb = (HttpWebRequest)HttpWebRequest.Create(targetUri);
System.Net.HttpWebResponse response = hwb1.GetResponse();
int status = (int)response.StatusCode;
if (status == 200)
{
Response.Write("Successfully transmitted" + status);
}
}
是否有任何其他替代方法可以确保消息 100% 提交。