简体   繁体   English

使用HttpClient Windows Phone处理布尔响应

[英]Handling a bool Response using HttpClient windows phone

I'm developing a windows phone app that generates a QRcode, when the code is scanned, then response has to come back as true, please look at my code and advice as i'm getting a false response even thought the other app has scanned the code. 我正在开发一个Windows Phone应用程序,该应用程序会生成QR码,当扫描该代码时,响应必须返回为真,请查看我的代码和建议,因为即使其他应用程序都已扫描,我也会得到错误的响应编码。

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
        {

        }
    }

上面的问题是由Windows Phone缓存引起的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM