httpWebRequest有不有缓存,怎么解决

chinull 2005-01-23 01:45:15
我在一个XML文件中存了若干Area,将其取出,作为参数,传递给自定义函数
GetUrlSource(string,string,string)该函数作用是获取一个带参数的web页。

但是问题是现在在“//处理source”处得到的结果都是用第一个节点的参数获取的Web页的处理结果。

同时如果我将GetUrlSource(Area.Value.ToString(),"","")中的Area.Value.ToString()替换成常数,能获取任意页面,这说明GetUrlSource()没有问题。

所以,怀疑foreach()的问题source=GetUrlSource(Area.Value.ToString(),"","");获取的值
是第一次获取的值,后面的值都是被缓冲了?我该怎么办啊。下面是foreach的代码

...
foreach (XmlNode Area in nodeList)
{
source=GetUrlSource(Area.Value.ToString(),"","");

end=source.Length;
//处理source
}
...
...全文
663 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
小马2012 2005-03-01
  • 打赏
  • 举报
回复
接分
chinull 2005-01-23
  • 打赏
  • 举报
回复
我觉得这是不是一个异步执行的请求啊(WebRequest/WebResponse)?才导致出了问题?现在没有办法了,理解不清楚windows里面的进程,按说应该网络请求是给了系统的一个专门的进程来处理,那这几个连续的请求是被这个进程怎么处理的呢?
chinull 2005-01-23
  • 打赏
  • 举报
回复
老哥,不行,问一下你的tmp参数是一个无用参数,怎么能让系统知道这是一个新的请求呢?因为这样一来所有的连接请求都多了一个参数,所以参数个数还是一样多,而url是一样的,怎么能够再次让系统执行新的请求,而不是用缓存呢?
孟子E章 2005-01-23
  • 打赏
  • 举报
回复
url后面可以加个随机数:例如

url="http://www.mysite.com/index.jsp?selectedArea=xxxx&tmp=" + (new System.Guid()).ToString("N");
)
chinull 2005-01-23
  • 打赏
  • 举报
回复
private string GetUrlSource(string selectedArea ,string selectedProvince,string selectedDistrict)
{
string msg ="";
try
{

HttpWebRequest loHttp =(HttpWebRequest) WebRequest.Create("http://www.mysite.com/index.jsp?selectedArea=" + HttpUtility.UrlEncode(selectedArea,System.Text.Encoding.GetEncoding("gb2312"))+"&selectedProvince="+ HttpUtility.UrlEncode(selectedProvince,System.Text.Encoding.GetEncoding("gb2312"))+"&selectedDistrict="+ HttpUtility.UrlEncode(selectedDistrict,System.Text.Encoding.GetEncoding("gb2312"))+"&selectedStation=");

WebResponse myResponse = loHttp.GetResponse();
Stream ReceiveStream =myResponse.GetResponseStream();
Byte[] read = new Byte[512];
int bytes = ReceiveStream.Read(read, 0, 512);
while (bytes > 0)
{
Encoding encode = System.Text.Encoding.Default;
msg += encode.GetString(read, 0, bytes);
bytes = ReceiveStream.Read(read, 0, 512);
}
myResponse.Close();
loHttp.Abort();
msg=msg.Substring(4096,msg.Length-6144);
}
catch
{
msg="error";
}

return msg;
}

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧