2016-06-24 13 views
0

Ich entwickle eine Windows Phone App, die einen QRcode generiert, wenn der Code gescannt wird, dann muss die Antwort als wahr zurückkommen, schauen Sie sich bitte meinen Code und Rat wie ich bin eine falsche Antwort erhalten, auch wenn die andere App den Code gescannt hat.Umgang mit einem Bool Antwort mit HttpClient Windows Telefon

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 
     { 

     } 
    } 

Antwort

0

Das obige Problem wird durch Windows-Telefon-Caching verursacht.