考虑以下函数:
public string Get(string url, string parameters = "", bool xml = false)
{
try
{
if(xml) { client.Headers["X-Requested-With"] = "XMLHttpRequest";
return client.DownloadString(url + "?" + parameters);
}
catch (WebException ex)
{
System.Console.WriteLine(ex.Message);
throw;
}
}对它的两个调用:
Get("http://www.host.com", "", true);
Get("http://www.host.com", "", false);第二个Get()调用是否设置了X-Requested With标头?这些头文件是否在每次调用WebClient.DownloadString函数后被“重置”,或者我必须手动将它们恢复为默认值?
发布于 2012-07-15 03:38:23
在调试代码之后,我得出的结论是,在这种情况下,设置的标头仍然存在,并且需要手动将它们恢复为默认值。
https://stackoverflow.com/questions/11486671
复制相似问题