gpt4 book ai didi

c# - System.Net.Http.HttpClient 超时似乎被忽略了

转载 作者:太空宇宙 更新时间:2023-11-03 15:33:53 25 4
gpt4 key购买 nike

我正在使用 Xamarin.iOS 版本:8.10.5.26(独立版)并面临一个非常奇怪的行为,即使用 HttpClient() 发送的请求超时:

以下代码尝试从 url 获取结果,超时时间为 60 秒(1 分钟),但是当请求被触发时,超时时间大约为 90 秒。调用电话时,我手动关闭网络连接以检查超时。据观察,它花费了 60 多秒。

代码

public async Task<Dictionary<string,object>> GetPatientDataASync (string lUsername)
{
var lDict = new Dictionary<string,object> ();
try {
string lQuerystring = "{Email: '" + lUsername + "'}";
String lUrl = String.Format (Constants.mURLPatient + "?where={0}", JObject.Parse (lQuerystring));
var lClient = new HttpClient ();
lClient.BaseAddress = new Uri (lUrl);
lClient.DefaultRequestHeaders
.Accept
.Add (new MediaTypeWithQualityHeaderValue ("application/json"));
lClient.DefaultRequestHeaders.Add ("X-Parse-Application-Id", Constants.mKeyParseAppId);
lClient.DefaultRequestHeaders.Add ("X-Parse-REST-API-Key", Constants.mKeyRestAPIKey);
lClient.Timeout = new TimeSpan (0, 1, 0);
var request = new HttpRequestMessage ();
request.Method = HttpMethod.Get;
if (Utility.isNetworkConnected ()) {
bool responseStatus = false;
await lClient.SendAsync (request)
.ContinueWith (responseTask => {
if (responseTask != null) {
var response = responseTask.Result;
if (response != null) {
if (response.IsSuccessStatusCode) {
var responseContent = response.Content;
if (responseContent != null) {
string responseString = responseContent.ReadAsStringAsync ().Result;
if (!string.IsNullOrWhiteSpace (responseString)) {
JObject json = JObject.Parse (responseString);
if (json != null) {
if (json ["results"].Any ()) {
Patient user = Patient.Instance;
user.objectId = json.SelectToken (@"results[0].objectId").Value<string> ();
user.Email = json.SelectToken (@"results[0].Email").Value<string> ();
user.Name = json.SelectToken (@"results[0].Name").Value<string> ();
user.IsNotificationsEnabled = json.SelectToken (@"results[0].IsNotificationsEnabled").Value<string> ();

Application.Current.Properties ["IsNotificationsEnabled"] = json.SelectToken (@"results[0].IsNotificationsEnabled").Value<string> ();

if (json.SelectToken (@"results[0].DeviceToken") != null) {
var deviceToken = json.SelectToken (@"results[0].DeviceToken").Value<JArray> ();
if (deviceToken != null)
user.DeviceToken = deviceToken.ToObject < List<string>> ();
} else {
user.DeviceToken = new List<string> ();
}

var doctors = json.SelectToken (@"results[0].MyDoctors").Value<JArray> ();
user.AllergicTo = json.SelectToken (@"results[0].AllergicTo").Value<string> ();
user.ContactNo = json.SelectToken (@"results[0].ContactNo").Value<string> ();
user.BloodGroup = json.SelectToken (@"results[0].BloodGroup").Value<string> ();
user.MyDoctors = doctors != null ? doctors.ToObject<List<string>> () : new List<string> ();
responseStatus = true;
} else
responseStatus = false;
}
}
}
}
}
}
});
lDict.Add (SUCCESS_CODE, responseStatus);
return lDict;
} else {
lDict.Add (NO_INTERNET, Constants.mStringNoInternetMessage);
return lDict;
}
} catch (Exception e) {
Debug.WriteLine (e.Message + "\n " + e.StackTrace);
lDict.Add (EXCEPTION_OCCURED, e);
return lDict;
}
}

如果我的代码有错误,请告诉我。这里也报告了同样的问题:-

  1. First link

  2. Second Link

最佳答案

这是一个已知错误,多年来已多次打开、关闭和重新打开。已经报道herehere .

关于c# - System.Net.Http.HttpClient 超时似乎被忽略了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32589013/

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