【发布时间】:2016-05-30 23:23:28
【问题描述】:
我正在尝试向 Google 位置 Api 发送一条 Http Get 消息,该 Api 应该具有诸如此类的 Json 数据
https://maps.googleapis.com/maps/api/geocode/json?address=Los%20Angeles,CA=AIzaSyDABt 正如您注意到的那样,响应是在 Json 中。我想对该 URL 进行 Http 调用并将 Json 内容保存在变量或字符串中。我的代码没有给出任何错误,但也没有返回任何内容
public async System.Threading.Tasks.Task<ActionResult> GetRequest()
{
var client = new HttpClient();
HttpResponseMessage response = await client.GetAsync("https://maps.googleapis.com/maps/api/geocode/json?address=Los%20Angeles,CA=AIzaSyDABt");
string data = response.Content.ToString();
return data;
}
我想使用 HttpClient() 或任何将发送 URL 请求的东西发送一个 Get 请求,然后将该内容保存到一个字符串变量中。任何建议都将不胜感激,我的代码再次没有错误,但没有返回任何内容。
【问题讨论】:
-
发出请求的是什么类型的应用程序?这对答案有很大影响。
-
这是一个 MVC4 应用程序,我基本上是在提交控制器操作时进行调用。我将在上面发布更多代码。
-
跟随api的树,例如获取你需要写的long_name,results.adress_components.long_name
标签: c# json asp.net-mvc-4 google-api