简体   繁体   English

必应地图未经授权的回应

[英]unauthorized response from bing maps

i'm tring to get the country and region based on a point in Bing maps API, i have created a trial public web key and used it .... but it gets me the following response ** 我正试图根据Bing maps API中的某个点来获取国家和地区,我已经创建了一个试用的公共Web密钥并使用了它..但是它得到了以下响应**

"Copyright © 2014 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation." “版权所有©2014 Microsoft及其供应商。保留所有权利。未经Microsoft Corporation的明确书面许可,不得访问此API,并且不得以任何方式使用,复制或传播此内容和任何结果。”

** when i enter the URL in my chrome browser i get the right response ... but in the debug i get that message . **当我在Chrome浏览器中输入URL时,我得到了正确的响应……但是在调试中,我得到了该消息。

that's my main method 那是我的主要方法

 try
            {
                Uri locationsRequest = CreateRequest(query,key);
                Response locationsResponse = MakeRequest(locationsRequest);
                ProcessResponse(locationsResponse);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.Read();
            }

there is my url creation function 有我的网址创建功能

    public static Uri CreateRequest(string queryString, string BingMapsKey)
    {
        Uri UrlRequest = new Uri(string.Format("http://dev.virtualearth.net/REST/v1/Locations?q={0}&key={1}", queryString, BingMapsKey));
        return (UrlRequest);
    }

and thas my ersponse function 和我的回应功能

           public static Response MakeRequest(Uri requestUrl)
    {
        try
        {

            HttpWebRequest request = WebRequest.Create(requestUrl) as HttpWebRequest;
            using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
            {
                if (response.StatusCode != HttpStatusCode.OK)
                    throw new Exception(String.Format(
                    "Server error (HTTP {0}: {1}).",
                    response.StatusCode,
                    response.StatusDescription));
                DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(Response));
                object objResponse = jsonSerializer.ReadObject(response.GetResponseStream());
                Response jsonResponse
                = objResponse as Response;
                return jsonResponse;
            }
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
            return null;
        }

    }

I know this is a bit late. 我知道这有点晚了。 But I encountered the same problem and the solution I found was not the code but in the data. 但是我遇到了同样的问题,发现的解决方案不是代码,而是数据。 Make sure that your queryString is a valid URL when combined with the VirtualEarth URL you are sending to Bing Maps. 与要发送到Bing Maps的VirtualEarth URL结合使用时,请确保queryString是有效URL。

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

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