Windows Phone 8 HttpClient未响应所有Post数据

时间:2014-02-16 13:50:16

标签: c# windows-phone-8 http-post

我想像这样发布字符串数据windwos phone 8:

using (var handler = new HttpClientHandler())
        {
            if (handler.SupportsAutomaticDecompression)
            {
                handler.AutomaticDecompression = DecompressionMethods.GZip |
                    DecompressionMethods.Deflate;
            }
            using (var client = new HttpClient(handler))
            {
                client.DefaultRequestHeaders.Accept.Add(
                    new MediaTypeWithQualityHeaderValue("application/json"));
                var fromUrlEncodedContet = 
                    new List<KeyValuePair<string, string>>()
                    {
                        new KeyValuePair<string, string>("aliasno1","01120"),
                        new KeyValuePair<string, string>("aliasno2", "89479"),
                        new KeyValuePair<string, string>("aliasno3", "1"),
                        new KeyValuePair<string, string>("myregion", "006"),
                        new KeyValuePair<string, string>("myregiontitle", "IZMIR")
                    };

                using (var response = await client.PostAsync("http://m.kentkart.com/kws.php", 
                    new  FormUrlEncodedContent(fromUrlEncodedContet)))
                {
                    if (response.IsSuccessStatusCode)
                    {
                        var data =  response.Content.ReadAsStringAsync().Result;
                    }
                }
            }
        }

当我点击按钮和断点数据时。我看到了像这样的回复数据;

  

{“time_webacc”:“1.6927719116211E-5 !!”,“refreshCount”:0,“time_HOST”:“4.0054321289062E-5!”,“servicetimediff”:5102,“timedifference”:“5102(主持人) “}

我没有收到所有数据。责任数据必须

balanceresult:“8,75” chargeAmt:“10” chargeresult:“20140125152910” 功能:“bs” refreshCount:0 servicetimediff:354 time_HOST:“0.3545618057251!” time_bal_stat:“0.0059030055999756!” time_balance:“0.34575796127319!” time_webacc:“0.0028519630432129 !!” timedifference:“341(ws)/ 354(host)” usageAmt:“2” usageresult:“20140126123248”

我做错了什么,但我不明白我的错误在哪里..

1 个答案:

答案 0 :(得分:1)

好像你发布了错误的参数

using (var handler = new HttpClientHandler())
{
    if (handler.SupportsAutomaticDecompression)
    {
        handler.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
    }

    using (var client = new HttpClient(handler))
    {
        client.DefaultRequestHeaders.Referrer = new Uri("http://m.kentkart.com/");
        client.DefaultRequestHeaders.Accept.Add(
            new MediaTypeWithQualityHeaderValue("application/json"));

        var fromUrlEncodedContet =
            new List<KeyValuePair<string, string>>()
        {
            new KeyValuePair<string, string>("func","bs"),
            new KeyValuePair<string, string>("val", "0112089479"),
            new KeyValuePair<string, string>("myregiontitle", "Izmir"),
            new KeyValuePair<string, string>("myregion", "006"),
        };

        using (var response = await client.PostAsync("http://m.kentkart.com/kws.php",
            new FormUrlEncodedContent(fromUrlEncodedContet)))
        {
            if (response.IsSuccessStatusCode)
            {
                var data = await response.Content.ReadAsStringAsync();
                dynamic obj = await JsonConvert.DeserializeObjectAsync(data);
                var balance = Convert.ToDecimal((string)obj.balanceresult, CultureInfo.CreateSpecificCulture("tr-TR"));
            }
        }
    }
}

BTW:服务器将balanceresult作为"8,75"返回。更正确的结果是8.75(没有" s)