为什么这个虚拟地球REST Url失败了? [英] Why is this virtualearth REST Url failing?

查看:60
本文介绍了为什么这个虚拟地球REST Url失败了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于p的代码。 Wrox的Pro Windows 8编程255 [http://p2p.wrox.com/book-professional-windows-8-programming-application-development-c-xaml-703/],我试着像这样调用virtualearth的REST API :



Based on code on p. 255 of Wrox's Pro Windows 8 Programming[http://p2p.wrox.com/book-professional-windows-8-programming-application-development-c-xaml-703/], I am trying to call virtualearth's REST API like so:

async internal static Task<CivicAddress> GetCivicAddress(Location location)
{
    HttpClient http = new HttpClient();
    StringBuilder sb = new StringBuilder("http://deb/virtualearth.net/REST/v1/Locations/");
    sb.Append(location.Latitude.ToString());
    sb.Append(",");
    sb.Append(location.Longitude.ToString());
    sb.Append("?o=xml&key=");
    sb.Append(App.BingMapsKey);

    HttpResponseMessage resp = await http.GetAsync(sb.ToString());
    resp.EnsureSuccessStatusCode();
    Stream strom = await resp.Content.ReadAsStreamAsync();

    XDocument xdoc = XDocument.Load(strom);

    XNamespace bmn = App.BingMapsNamespace;
    String addressLine = (from l in xdoc.Descendants(bmn + "AddressLine") select l).First().Value;
    String municipality = (from l in xdoc.Descendants(bmn + "Locality") select l).First().Value;
	. . .





...(sb.ToString())最终成为(如果纬度为44且经度为-122) ):





...which (sb.ToString()) ends up being (if the latitude is 44 and the longitude is -122):

http://dev/virtualearth.net/REST/v1/Locations/44,-122?o=xml&key=[my bing maps key]





然而,代码是轰炸,永远不会超过 * HttpResponseMessage resp = await http.GetAsync(sb.ToString()); *line。



我想知道这个网址是否属虚假,并检查了该网站的网站是否存在错误,但一无所获。我直接将URL输入浏览器。它告诉我,** ERR_NAME_NOT_RESOLVED **



我在代码中添加了一个catch块:





However, the code is bombing out, and never getting past the "*HttpResponseMessage resp = await http.GetAsync(sb.ToString());*" line.

I wondered if the URL was bogus, and checked the book's site for errate, but found nothing. I entered the URL directly into a browser. It tells me, **ERR_NAME_NOT_RESOLVED**

I added a catch block to the code:

catch (HttpRequestException hre)
{
    Debug.WriteLine("Exception in GetCivicAddress(): {0} Inner Ex = {1}, Stack Trace = {2}",
        hre.Message, hre.InnerException.ToString(), hre.StackTrace);
}





...并获取, GetCivicAddress()中的异常:错误发送请求时发生。

内部Ex = System.Net.WebException:无法解析远程名称:System.Net.HttpWebRequest.EndGetResponse上的'dev'

(IAsyncResult asyncResult)

在System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar),

Stack Trace = at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)
在System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()


在Photrax.PhotraxUtils。< getcivicaddress> d__f.MoveNext()

在Photrax.exe中发生'System.NullReferenceException'类型的第一次机会异常




大规模注射Corona或者w帽子在这里?



...and get, "Exception in GetCivicAddress(): An error occurred while sending the request.
Inner Ex = System.Net.WebException: The remote name could not be resolved: 'dev'
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.Http.HttpClientHandler.GetResponseCallback(IAsyncResult ar),
Stack Trace = at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Photrax.PhotraxUtils.<getcivicaddress>d__f.MoveNext()
A first chance exception of type 'System.NullReferenceException' occurred in Photrax.exe


Has virtualearth been hit by a mass injection of Corona, or what is going on here?

推荐答案

网址似乎有误。



支票 - 通过点的位置 [< a href =http://api-portal.anypoint.mulesoft.com/microsoft/api/bing-maps-geocode-service-api/docs/reference/location-via-pointtarget =_ blanktitle =新窗口> ^ ]
URL seems to be wrong.

Check - Location via Point[^]


评论者提供的其中一个链接引导我到另一个链接这里,我最终知道这一点,它有效:



One of those links provided by a commenter led me to another link here , from which I ended up wit this, which works:

HttpClient http = new HttpClient();
String httpqry = String.Format("http://dev.virtualearth.net/REST/v1/Locations/{0},{1}?o=xml&key={2}", location.Latitude.ToString(), location.Longitude.ToString(), App.BingMapsKey);

HttpResponseMessage resp = await http.GetAsync(httpqry);
resp.EnsureSuccessStatusCode();

Stream strom = await resp.Content.ReadAsStreamAsync();

XDocument xdoc = XDocument.Load(strom);

XNamespace bmn = App.BingMapsNamespace;
String addressLine = (from l in xdoc.Descendants(bmn + "Address") select l).First().Value;
String municipality = (from l in xdoc.Descendants(bmn + "Locality") select l).First().Value;
String stateProv = (from l in xdoc.Descendants(bmn + "AdminDistrict") select l).First().Value;
String postalCode = (from l in xdoc.Descendants(bmn + "PostalCode") select l).First().Value;
String country = (from l in xdoc.Descendants(bmn + "CountryRegion") select l).First().Value;





新网址与旧网址的区别如何,我可以'告诉 - 也许是它的构建方式,还是......?无论如何,它都有效,所以我很高兴并将继续接下来的挑战。



How the new URL differs from the old, I can't tell - maybe it's in how it's built, or...? At any rate, it works, so I'm happy and will move on to the next challenge.


这篇关于为什么这个虚拟地球REST Url失败了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆