WebRequest在IIS 6上没有响应

时间:2012-03-21 19:56:02

标签: c# asp.net iis-6 iis-express

我有一个使用HTTPWebRequest的应用程序,并在开发框上正常工作。此框正在运行IIS Express 7.5

将此应用程序部署到另一台服务器(运行IIS 6)时,GetResponse()永远不会返回。没有错误消息,没有超时或其他任何内容。示例代码如下:

        string url = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.ApplicationPath + String.Format("/FolderName/PageName.aspx");


        WebRequest request = WebRequest.Create(url);
        request.Method = "GET";
        request.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;

        request.Headers.Add("x", _x);
        request.Headers.Add("y", _y);
        request.Headers.Add("z", _z);

        // this line never returns in IIS 6
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();

        Stream dataStream = response.GetResponseStream();

        StreamReader reader = new StreamReader(dataStream);


        string s = reader.ReadToEnd();

        reader.Close();
        dataStream.Close();
        response.Close();

1 个答案:

答案 0 :(得分:0)

原来这是由于IIS6服务器上的SSL证书无效......

得到的方法就在这里(仅用于测试目的):How do I use WebRequest to access an SSL encrypted site using https?