2013-02-09 74 views
0

我正在製作一個簡單的應用程序,使用http獲取請求將位置數據發送到服務器。 問題是請求僅在第一次進行,儘管它位於positionchanged事件處理程序中。通過獲取發送位置

這是我的代碼。我找不到它有什麼問題。

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Net; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Documents; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Animation; 
using System.Windows.Shapes; 
using Microsoft.Phone.Controls; 
using System.Device.Location; 

namespace kechap 
{ 
    public partial class MainPage : PhoneApplicationPage 
    { 
     GeoCoordinateWatcher gw = new GeoCoordinateWatcher(); 

     Uri url = new Uri("http://127.0.0.1:5000/upload/1e3fae069dd62fa1641183cd77092ed2053a0e75/1/2"); 


     // Constructor 
     public MainPage() 
     { 
      InitializeComponent(); 
      gw.MovementThreshold = 10; 
      gw.PositionChanged += (s, e) => 
      { 
       MyMap.Center = e.Position.Location; 
       MyPushpin.Location = e.Position.Location; 

       WebClient wc = new WebClient(); 

       wc.OpenReadAsync(url); 
       wc.OpenReadCompleted += (ss, ee) => 
       { 
       };   
      }; 

      gw.Start(); 
     } 

    } 
} 

回答

2

在一個猜測中,我會說在你發佈的代碼中的URI不會在調用之間改變,在第一次之後從緩存中解析出來。我建議你使用舊的黑客追加一個參數,並給它一個隨着每次調用而改變的值(例如,你似乎想要報告的位置)。

+0

這是我沒有預料到的。我有固定的網址來測試它是否有效,這讓我失望了。 – kechapito 2013-02-09 13:59:46

+0

在網絡應用緩存的早期,我的存在是個禍根。有很多方法可以禁止它,包括將URL(正如我已經提到的)添加到各種HTML元標記和指令中。篡改URL是醜陋但可靠的。不利的一面是它膨脹了瀏覽器緩存。 – 2013-02-21 04:04:58