1

问题是关于使用 google api 的 json 格式的位置请求,如下所示。它总是返回“{}”。这段代码已经正常工作了,有什么改变?下面的示例中是否有任何遗漏。

谢谢。

   static void Main(string[] args)
    {
        var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://www.google.com/loc/json");
        httpWebRequest.ContentType = "text/json";
        httpWebRequest.Method = "POST";

        using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
        {
            string json = "{\"version\":\"1.1.0\",\"host\":\"maps.google.com\"" +
                         ",\"cell_towers\":[{\"cell_id\":25070,\"location_area_code\":4474" +
                         ",\"mobile_country_code\":460,\"mobile_network_code\":0}]" +
                         ",\"wifi_towers\":[{}]}";

            streamWriter.Write(json);
        }
        var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
        using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
        {
            var responseText = streamReader.ReadToEnd();
            //Now you have your response.
            //or false depending on information in the response
            Console.WriteLine("result 1:");
            Console.WriteLine(responseText);
            Console.ReadKey();
            return;
        }
    }
4

0 回答 0