0

我正在为我们的应用程序编写一个 SMS 功能。没有错误,但它不符合我的期望。使用数据集我得到多个手机号码,然后我需要将消息传递给所有这些手机号码。

1.使用 Response.Redirect 仅发送 1 条消息,其他不发送。(发送第 1 条消息后,它转到该页面)

下面部分编码

DataSet DistDs = _distsms.GetAllDistributionList(UnitId, isShot, gameId, animalTypeId);
if(DistDs.Tables[0].Rows.Count > 0)
{   
    ContactNo = Convert.ToInt32(DistDs.Tables[0].Rows[0]["ContactNumber"]);
    foreach (DataRow row in DistDs.Tables[0].Rows)
    {
        if (row["ContactNumber"].ToString() != "")
        {
            try
            {
                Response.Redirect("http://sms.gatewaysite.com/api/mt?msisdn=" + row["ContactNumber"].ToString() +
                                  "&body=" + msgOut + "&sender=" + shortcode +
                                  "&key=ertyertyer&product_id=4563456&operator=" + oppp + "&country=aaaaa");
            }
            catch(Exception ee)
            {
                string a = ee.Message;
                //continue;
            }
        }
    }
}
4

2 回答 2

1

Response.Redirect这样做 - 它重定向整个响应。

对于您要尝试做的事情,请使用HttpWebRequest

于 2012-12-07T05:55:33.533 回答
0

将数据发送到远程服务器是一种不好的方式。尝试使用 Web 服务调用或 Web Api 调用。您可以在其中以 JSON 格式发送数据。AFIK 您正在结束响应流。

或者,您可以通过调用 WebRequestHTTP WebRequest

来自 MSDN

WebRequest request = WebRequest.Create ("http://www.contoso.com/PostAccepter.aspx ");
            // Set the Method property of the request to POST.
            request.Method = "POST";
            // Create POST data and convert it to a byte array.
            string postData = "This is a test that posts this string to a Web server.";
            byte[] byteArray = Encoding.UTF8.GetBytes (postData);
            // Set the ContentType property of the WebRequest.
            request.ContentType = "application/x-www-form-urlencoded";
            // Set the ContentLength property of the WebRequest.
            request.ContentLength = byteArray.Length;
            // Get the request stream.
            Stream dataStream = request.GetRequestStream ();
            // Write the data to the request stream.
            dataStream.Write (byteArray, 0, byteArray.Length);
            // Close the Stream object.
            dataStream.Close ();
            // Get the response.
            WebResponse response = request.GetResponse ();
            // Display the status.
            Console.WriteLine (((HttpWebResponse)response).StatusDescription);
            // Get the stream containing content returned by the server.
            dataStream = response.GetResponseStream ();
            // Open the stream using a StreamReader for easy access.
            StreamReader reader = new StreamReader (dataStream);
            // Read the content.
            string responseFromServer = reader.ReadToEnd ();
            // Display the content.
            Console.WriteLine (responseFromServer);
            // Clean up the streams.
            reader.Close ();
            dataStream.Close ();
            response.Close ();
于 2012-12-07T05:56:18.360 回答