我正在使用以下代码:
var request = (HttpWebRequest)WebRequest.Create(new Uri(addy));
request.UserAgent = "Mozilla/5.0 (Windows; U; MSIE 9.0; WIndows NT 9.0; en-US))";
request.BeginGetResponse(
r =>
{
var httpRequest = (HttpWebRequest)r.AsyncState;
var httpResponse = (HttpWebResponse)httpRequest.EndGetResponse(r);
using (var reader = new StreamReader(httpResponse.GetResponseStream()))
{
var response = reader.ReadToEnd();
results = (String)response;
}
}, request);
addy 是:http ://maps.googleapis.com/maps/api/geocode/xml?address=limavady&sensor=false
results 只是一个全局字符串,我想将 Web 请求的结果输出到该字符串。
问题只是我不断得到一个空值输出到结果,我检查了网址,它是正确的,应该有输出。
对此有任何想法,或者如果您能指出正确的方向,我将不胜感激