使用Xamarin Forms应用程序,我从PHP Web API获得了一些数据:
[
{
"userId": 1,
"id": 1,
}
]
当我将服务器上的JSON属性的某些名称更改为:
[
{
"uId": 1,
"id": 1,
}
]
当我从Xamarin应用程序调用API时,它仍在缓存并获取旧的JSON格式,但Postman正在获取正确的数据(第二个JSON格式)。
我这样声明了HttpClient对象:
public static readonly HttpClient client = new HttpClient(new NativeMessageHandler() { Timeout = new TimeSpan(0, 0, 9), EnableUntrustedCertificates = true, DisableCaching = true });
我这样使用它:
public async Task<List<ChoosenMagazin>> getOtherMagsAsync(string apiName)
{
try
{
HttpResponseMessage response = await client.GetAsync(url + apiName);
string responseString = await response.Content.ReadAsStringAsync();
generalResponse result = Newtonsoft.Json.JsonConvert.DeserializeObject<generalResponse>(responseString);
if (result.status == 1)
{
var mags = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ChoosenMagazin>>(result.msg.ToString());
return mags;
}
return null;
}
catch (Exception ex)
{
return null;
}
}