Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# GetResponse()在开发机器上工作,而不是在客户端机器上_C#_Winforms_Webrequest - Fatal编程技术网

C# GetResponse()在开发机器上工作,而不是在客户端机器上

C# GetResponse()在开发机器上工作,而不是在客户端机器上,c#,winforms,webrequest,C#,Winforms,Webrequest,我尝试在我的开发机器(XP)上使用WebRequest.GetResponse(),它工作正常,我可以从URL读取响应流,但当URL相同时,在两台客户端机器(Windows 7)上编译的代码失败。WebException.Status为“网络请求不受支持”。为什么在尝试访问同一URL时会出现这种情况?WebException由GetResponse方法触发。在catch子句中,response对象和WebException.response对象都为null。如何进一步诊断问题 WebReques

我尝试在我的开发机器(XP)上使用WebRequest.GetResponse(),它工作正常,我可以从URL读取响应流,但当URL相同时,在两台客户端机器(Windows 7)上编译的代码失败。WebException.Status为“网络请求不受支持”。为什么在尝试访问同一URL时会出现这种情况?WebException由GetResponse方法触发。在catch子句中,response对象和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.
WebRequest请求=null;
HttpWebResponse响应=null;
流数据流=null;
StreamReader=null;
String responseFromServer=String.Empty;
stringhttp=string.Empty;
int超时=30000;
string errorMsg=string.Empty;
http=this.URLstring;
布尔误差=假;
尝试
{
request=System.Net.WebRequest.Create(http);
request.Timeout=超时;
response=(System.Net.HttpWebResponse)request.GetResponse();
}
捕获(System.Net.WebException wex)
{
错误=真;
errorMsg=wex.Message+“”+wex.Status.ToString();
如果(wex.Response!=null)
{
WebHeaderCollection hdrs=wex.Response.Headers;
对于(int i=0;i
这可能是一个特权问题。要测试这一点,请以管理员身份在Win7下运行应用程序。

请缩进您的代码-这样更容易阅读:)使用关键字也是个好主意。)发布(完整)错误消息文本可能会有所帮助。@Shrike您在哪里看到使用的HttpStatus?在应用程序的某个地方放一张“在我的机器上工作”的图片:p JK!