我正在使用HttpClient與Web服務進行通信以進行發送/接收(JSON格式的響應)。但是我在接收數據時遇到了一些問題。我每5分鐘撥打一次網絡服務,使用HttpClient在我的Windows手機上刷新內容,但響應一次又一次。爲了獲得新的回覆,我需要退出應用程序並再次致電服務。 HttpClient是否需要刷新或清除數據過程?我是否需要實施其他一些措施才能每次獲得新的刷新結果? 請建議。下面是我的實現HttpClient響應未獲取刷新
public async Task<string> GetMyData(string urlToCall)
{
try
{
using (HttpClient httpClient = new HttpClient())
{
httpClient.Timeout = TimeSpan.FromMilliseconds(double.Parse(30000));
HttpRequestMessage request = new HttpRequestMessage(System.Net.Http.HttpMethod.Get, urlToCall);
var response = await httpClient.SendAsync(request);
if (response.StatusCode == HttpStatusCode.OK)
{
var responseString = await response.Content.ReadAsStringAsync();
return responseString;
}
else
{
return string.Empty;
}
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("Exception => RestfulWebService =>GetMyData: " + ex.Message);
return string.Empty;
}
}
也許這是幫忙嗎? http://stackoverflow.com/questions/21620853/why-does-the-httpclient-always-give-me-the-same-response/21624609#21624609 –