gpt4 book ai didi

windows-phone-7 - 为什么 DownloadStringCompleted 方法总是在 Windows Phone 7 中返回相同的结果?

转载 作者:行者123 更新时间:2023-12-04 07:06:42 25 4
gpt4 key购买 nike

我们面临一个问题,即 DownloadStringCompleted 方法总是在 Windows Phone 7 中返回相同的结果?

首先通过服务绑定(bind)挂起的请求。显示列表框中的请求放置了两个按钮。当单击那个调用接受服务时,该服务更新表。在调用显示先前结果的待处理请求服务时再次调用。为什么请告诉我...

代码:

private void getpendingrequests()
{
WebClient wcgetfriends = new WebClient();
wcgetfriends.DownloadStringAsync(
new Uri("http://{ipaddress}/Network/Reccords/GetFriends?userid=" + userId));
wcgetfriends.DownloadStringCompleted +=
new DownloadStringCompletedEventHandler(
wcgetfriends_DownloadStringCompleted);
}



void wcgetfriends_DownloadStringCompleted(object sender,
DownloadStringCompletedEventArgs e)
{

String resultgetfriends = null, responseCode = null;
using (var reader = new StringReader(e.Result))
{
resultgetfriends = reader.ReadToEnd();
}
XmlReader xmlDoc = XmlReader.Create(new MemoryStream(System.Text.UTF8Encoding.UTF8.GetBytes(resultgetfriends)));

while (xmlDoc.Read())
{
if (xmlDoc.NodeType == XmlNodeType.Element)
{

if (xmlDoc.Name.Equals("ResponseCode"))
{
responseCode = xmlDoc.ReadInnerXml();

}

}

}
if (Convert.ToInt32(responseCode) == 200)
{

string result1 = e.Result.ToString();

XDocument xmlDocu = XDocument.Load(new MemoryStream(System.Text.UTF8Encoding.UTF8.GetBytes(result1)));

interestrates = (from rts in xmlDocu.Descendants("Friend")

select new SampleCheckedData
{

Id = (string)rts.Element("userid"),
Name = (string)rts.Element("name"),
Icon = (string)rts.Element("imageurl"),

}).ToObservableCollection<SampleCheckedData>();


this.lstFriendRequuest.ItemsSource = interestrates;

}
if (Convert.ToInt32(responseCode) == 201)
{
MessageBox.Show("UserId is not type of integer");
}
if (Convert.ToInt32(responseCode) == 202)
{
MessageBox.Show("User not exists");
}
if (Convert.ToInt32(responseCode) == 203)
{
MessageBox.Show("No Pending Requests");
}

}

private void requestaccept()
{
WebClient wcacceptrequest = new WebClient();
wcacceptrequest.DownloadStringAsync(
new Uri("http://{ipaddress}/Network/Reccords/FriendRequestAcceptance?userid=" + userId + "&frienduserid=" + _id + "&acceptid=" + 1));
wcacceptrequest.DownloadStringCompleted +=
new DownloadStringCompletedEventHandler(
wcacceptrequest_DownloadStringCompleted);
Image b = sender as Image;
var res = interestrates.Where(a => a.Id.Equals(((System.Windows.FrameworkElement)(e.OriginalSource)).Tag)).ToList();
if (res.Count == 1)
interestrates.Remove(res.First());
}

void wcacceptrequest_DownloadStringCompleted(object sender,
DownloadStringCompletedEventArgs e)
{

String resultaccept = null, responseCode = null;
using (var reader = new StringReader(e.Result))
{
resultaccept = reader.ReadToEnd();
}
XmlReader xmlDoc = XmlReader.Create(new MemoryStream(System.Text.UTF8Encoding.UTF8.GetBytes(resultaccept)));

while (xmlDoc.Read())
{
if (xmlDoc.NodeType == XmlNodeType.Element)
{

if (xmlDoc.Name.Equals("ResponseCode"))
{
responseCode = xmlDoc.ReadInnerXml();

}

}

}
if (Convert.ToInt32(responseCode) == 200)
{

lstFriendRequuest.ItemsSource = "";
interestrates = new ObservableCollection<SampleCheckedData>();
bindGetFriends();

}
if (Convert.ToInt32(responseCode) == 201)
{
MessageBox.Show("UserId is not type of integer");
}
if (Convert.ToInt32(responseCode) == 202)
{
MessageBox.Show("Friend Id not type of integer");
}
if (Convert.ToInt32(responseCode) == 203)
{
MessageBox.Show("Accept id not type of integer");
}

}

请告诉我为什么在 bindfriends 方法中得到以前的结果......

最佳答案

这几乎可以肯定是由手机或某些网络代理中的缓存引起的。

为了防止缓存,您可以尝试做几件事 - 如果您想始终禁用缓存,那么最快的方法之一就是在 GET 请求的末尾添加一个唯一的数字 - 例如

                WebClient wcgetfriends = new WebClient();
wcgetfriends.DownloadStringCompleted += wcgetfriends_DownloadStringCompleted;
wcgetfriends.DownloadStringAsync(
new Uri(
"http://{ipaddress}/Network/Reccords/GetFriends?userid="
+ userId
+ "&ignored="
+ DateTime.UtcNow.Ticks));

还有其他类似的问题和答案:

关于windows-phone-7 - 为什么 DownloadStringCompleted 方法总是在 Windows Phone 7 中返回相同的结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11009112/

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