0

アプリケーションの SMS 関数を作成しています。エラーはありませんが、期待どおりではありません。データセットを使用して複数の携帯電話番号を取得しているため、これらすべての携帯電話番号にメッセージを渡す必要があります。

1.Response.Redirectを使用すると、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 は応答ストリームを終了しています。

または、次の方法で WebRequest を呼び出すこともできますHTTP 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 に答える