2012-12-07 46 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();