2012-12-07 47 views
0

我正在为我们的应用程序编写一个SMS函数。没有错误,但它不符合我的期望。 使用数据集,我得到多个移动号码,然后我需要通过messaage到所有这些手机号码。发送Response.Redirect只发送了1条消息

只有1

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; 
      } 
     } 
    } 
} 

部分

+0

请检查出的[Response.Redirect的]描述(http://msdn.microsoft.com/en-us/library/ a8wa7sdt(v = vs.100).aspx)在MSDN - 也许它不是你需要的方法。目前还不清楚你试图通过代码来达到什么目的(它的行为与你编码的行为完全一样)。 –

+0

@AlexeiLevenkov让我们说数据集返回2行然后我拿那2手机号码(msisdn)和使用response.redirect它发送消息到所有这些numbers.But只有1消息发送.. –

+0

Response.Redirect不发送短信或任何它只是立即返回302作为参数的位置。我*不知道*如果您需要使用此调用,但作为您的示例,它的行为是令人信服的。 Mayby你需要从服务器发送请求作为答案建议(使用'WebClient' /'HttpWebRequest')... –

回答

1

Response.Redirect不只是它 - 重定向整个响应。

对于你想要做什么,使用HttpWebRequest

0

它的坏的方式将数据发送到远程服务器。尝试使用Web服务调用或Web Api调用。您可以在这里以JSON格式发送数据。 AFIK您将结束响应流。

替代地可以通过HTTP WebRequest

调用的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();