gpt4 book ai didi

android - 在 Android 设备 Xamarin 上调试时请求无效

转载 作者:行者123 更新时间:2023-11-29 16:45:39 25 4
gpt4 key购买 nike

我正在用 Xamarin Forms 编写一个项目,今天我们在 Android 设备上试用我们的应用程序。我们对 googleAPI 的请求停止工作。这是代码:

HttpWebRequest webRequest = WebRequest.Create(@"https://maps.googleapis.com/maps/api/place/search/json?location=" + position.Latitude + "," + position.Longitude + "&radius=1000&types=bar&sensor=false&key=APIKEY") as HttpWebRequest;
webRequest.Method = "GET";
webRequest.BeginGetResponse(new AsyncCallback(RequestCompleted), webRequest);

然后:

var request = (HttpWebRequest)result.AsyncState;
var response = (HttpWebResponse)request.EndGetResponse(result);
using (var stream = response.GetResponseStream())
{
var r = new StreamReader(stream);
var resp = r.ReadToEnd();
}

我们得到响应并将其更改为 json。在电脑上它工作正常,但在 Android 上它说 INVALID REQUEST。有人使用 Xamarin 并知道如何解决它吗?

最佳答案

如果非要我猜的话,我会猜,你手机上的区域设置/语言与你电脑上的不同。

HttpWebRequest webRequest = WebRequest.Create(@"https://maps.googleapis.com/maps/api/place/search/json?location=" + position.Latitude + "," + position.Longitude + "&radius=1000&types=bar&sensor=false&key=APIKEY") as HttpWebRequest; 

...n="+ position.Latitude + ","+ position.Longitude + "&ra... 有隐含的 ToString() 产生本地化输出。但是 google API 需要带有 . 作为小数点分隔符的值。

追加 .ToString("G", CultureInfo.InvariantCulture)

HttpWebRequest webRequest = WebRequest.Create(@"https://maps.googleapis.com/maps/api/place/search/json?location=" + 
position.Latitude.ToString("G", CultureInfo.InvariantCulture) +
"," + position.Longitude.ToString("G", CultureInfo.InvariantCulture) +
"&radius=1000&types=bar&sensor=false&key=APIKEY") as HttpWebRequest;

关于android - 在 Android 设备 Xamarin 上调试时请求无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48428702/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com