Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/257.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# 使用ASP.net登录后将文件获取到客户端计算机_C#_Asp.net_File_Remote Access - Fatal编程技术网

C# 使用ASP.net登录后将文件获取到客户端计算机

C# 使用ASP.net登录后将文件获取到客户端计算机,c#,asp.net,file,remote-access,C#,Asp.net,File,Remote Access,我有一个要求登录凭据的url。输入正确凭据后,.csv文件将自动下载到用户计算机。我在asp.net中编写了一个代码,它下载了文件,但文件的内容有误,它显示了一些HTML内容。我正在使用以下代码: string url = "https://www.abc.com/asdasdxcss/actionlist2.csv"; string FSourceFilePath = url.Substring(url.LastIndexOf('/') + 1);

我有一个要求登录凭据的url。输入正确凭据后,.csv文件将自动下载到用户计算机。我在asp.net中编写了一个代码,它下载了文件,但文件的内容有误,它显示了一些HTML内容。我正在使用以下代码:

 string url = "https://www.abc.com/asdasdxcss/actionlist2.csv";
            string FSourceFilePath = url.Substring(url.LastIndexOf('/') + 1);
            WebRequest request = WebRequest.Create(url);
            request.Credentials = new NetworkCredential("temp", "test", "");
            // Get the response.
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            string respurlpath = "";
            respurlpath = response.ResponseUri.AbsoluteUri;
            WebRequest request5 = WebRequest.Create(respurlpath);
            request5.Credentials = new NetworkCredential("temp", "test", "");
            HttpWebResponse response5 = (HttpWebResponse)request.GetResponse();
            Stream dataStream = response.GetResponseStream();

            int bytesRead; byte[] buffer = new byte[4 * 1024];
            bytesRead = dataStream.Read(buffer, 0, buffer.Length);

            Server.ScriptTimeout = 30 * 60;
            Response.Buffer = false;
            Response.BufferOutput = false;
            Response.Clear();
            Response.ContentType = "text/csv";
            Response.AppendHeader("Content-Disposition", "attachment; filename=Test.csv");
            if (response5.ContentLength != -1)
                Response.AppendHeader("Content-Length", response5.ContentLength.ToString());

            while (bytesRead > 0 && Response.IsClientConnected)
            {
                Response.OutputStream.Write(buffer, 0, bytesRead);
                bytesRead = dataStream.Read(buffer, 0, buffer.Length);
            }



            if (dataStream != null) dataStream.Close();
            Response.End();
我的代码下载的文件内容:

       <html>
    <head>
        <META HTTP-EQUIV="expires" CONTENT="0">
    </head>
    <body>
        <form method="POST" enctype="application/x-www-form-urlencoded" action="/nidp/saml2/sso?id=157&sid=0&option=credential&sid=0"></form>
        <script language="JavaScript">
            <!--
                document.forms[0].submit();
            -->
        </script>
    </body>
</html>

实际下载的文件的html是什么样子的?这是一个自定义404错误页面还是类似的页面?请发布HTML,以便我们了解下载的内容。请参阅我的编辑以获取我得到的输出。我看到的是,链接为您提供了一个HTML表单,即提供文件下载的表单。这就像两步走的动作。我敢打赌,如果你再次以这种形式发布url,你将得到预期的文件。如何做到这一点@保罗红疹
parentID    Action_status   
123           True