0

如何在没有硬编码的情况下给出路径?

        HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create("http://lms.nsbm.lk/file.php/45/MIS_Notes/filename.pdf");

        getRequest.CookieContainer = new CookieContainer();
        getRequest.CookieContainer.Add(MoodleSessioncookie);
        getRequest.CookieContainer.Add(MoodleSessiontestcookie);
        getRequest.CookieContainer.Add(moodidcookie);

        HttpWebResponse form = (HttpWebResponse)getRequest.GetResponse();
        Stream responseReader = form.GetResponseStream();

        FileStream fs = File.Create("HardCoded Pdf File Name");
        byte[] data = new byte[512];
        int redcount = responseReader.Read(data, 0, data.Length);
        while (redcount > 0)
        {
            fs.Write(data, 0, redcount);
            redcount = responseReader.Read(data, 0, data.Length);
        }
        fs.Close();
        responseReader.Close();
4

0 回答 0