我尝试在我的开发机器(XP)上使用WebRequest.GetResponse()并且它正常工作,我可以从URL读取响应流,但是当URL是两个客户端计算机(Windows 7)时,编译的代码会失败相同。 WebException.Status是“不支持网络请求”。为什么会在尝试访问同一个网址时出现这种情况? WebException由GetResponse方法触发。在catch子句中,响应对象和WebException.Response对象都为null。我该怎么做才能进一步诊断问题?
WebRequest request = null;
HttpWebResponse response = null;
Stream dataStream = null;
StreamReader reader = null;
String responseFromServer = string.Empty;
string http = string.Empty;
int timeOut = 30000;
string errorMsg = string.Empty;
http = this.URLstring;
bool error = false;
try
{
request = System.Net.WebRequest.Create(http);
request.Timeout = timeOut;
response = (System.Net.HttpWebResponse)request.GetResponse();
}
catch (System.Net.WebException wex)
{
error = true;
errorMsg = wex.Message + " " + wex.Status.ToString();
if (wex.Response != null)
{
WebHeaderCollection hdrs = wex.Response.Headers;
for (int i = 0; i < hdrs.Count; i++)
errorMsg += Environment.NewLine + hdrs.Keys[i] + ", " + hdrs[i];
}
}
// Code to read the response stream goes here. it works on development machine.
答案 0 :(得分:2)
这可能是一种特权问题。要测试它,请在Win7'作为管理员'下运行应用程序