2016-06-24 25 views
0

我正在開發一個Windows手機應用程序,生成一個QRcode,當代碼掃描,然後響應必須回來爲真,請看看我的代碼和建議,因爲我即使認爲其他應用程序已經掃描了代碼也會得到錯誤的回覆。處理布爾響應使用HttpClient窗口電話

private async void queryQRCode(string code) 
    { 
     try 
     { 
      using (var client = new HttpClient()) 
      { 
       client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); 
       var authorisationHeader = GenerateBasicAuthorizationParameter("merchant-" + ObjUserData.MerchantId, ObjUserData.PassApiPassword); // 12ED5A5F2B38ACCBE437731BB2AC1F30 35A09A5C2AE97F055A0FDAEDA5A7093D 

       //Console.WriteLine ("http content - " + httpContent.ReadAsStringAsync().Result); 
       HttpResponseMessage httpResponse = new HttpResponseMessage(); 

       // Do the actual request and await the response 
       client.DefaultRequestHeaders.Authorization = authorisationHeader; 
       var f = QueryCodeUrl + "/" + code + "/scanned"; 

       httpResponse = await client.GetAsync(new Uri(f)); 
       //httpResponse.EnsureSuccessStatusCode(); 

       // If the response contains content we want to read it! 
       if (httpResponse.Content != null) 
       { 
        var responseContent = await httpResponse.Content.ReadAsStringAsync(); 

        // From here on you could deserialize the ResponseContent back again to a concrete C# type using Json.Net 
        Debug.WriteLine(responseContent); 

        try 
        { 
         ScannedCodeResult res = JsonConvert.DeserializeObject<ScannedCodeResult>(responseContent); 
         Debug.WriteLine("RETURNED RESPONSE IS "+res.scanned.ToString()); 


         if (res.scanned == false) 
         { 
          queryQRCode(code); 

         } 
         else 
         { 
          Debug.WriteLine("YAY!!!! The User has successfully scanned the application"); 



         } 
        } 
        catch (Exception ex) 
        { 
         Debug.WriteLine(ex.Message + ex.StackTrace); 
        } 
        // var qrResponse = (VcsMasterPassService.MasterPassModels.QRCodeResponse)JsonConvert.DeserializeObject (responseContent, typeof(VcsMasterPassService.MasterPassModels.QRCodeResponse)); 
        // CreateQRCodeImage (qrResponse.code); 
       } 

      } 
     } 
     catch (Exception ex) 
     { 
      Debug.WriteLine(ex.Message + ex.StackTrace); 
     } 
     finally 
     { 

     } 
    } 

回答

0

上面的問題是由windows手機緩存引起的。