Skip to content

Download The File After Logging IN

Lukasz Grygiel

Asked Jul 26, 2013, 1:51 AM EDT7 answers
Share
LinkedInX
Welcome
I have the following problem, I want to automate the process of downloading the xml file of the site by the program but unfortunately I do not know what the problem is that it gets me to the page rather than the file ....

How do I do now:

Logs:
Username: testtest
password: awdsa


contents of the file should be this:

<? xml version = "1.0"?>
<teams/>


Unfortunately, the code that I wrote is not downloading this file, only that page service ....
Can anyone help me ..... HELP (F1. .....)


CODE

 CookieContainer cookies = new CookieContainer();
                //POST
                HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://www.ligatestowanba.ligspace.pl/index.php?pa=Admin&mod=Users&ac=Login");
                request.Method = "POST";
                request.CookieContainer = cookies;
                string loginData = String.Format("username=testtest&password=awdsa");
                request.ContentType = "application/x-www-form-urlencoded";
                byte[] loginDataBytes = Encoding.ASCII.GetBytes(loginData);
                Stream postData = request.GetRequestStream();
                postData.Write(loginDataBytes, 0, loginDataBytes.Length);
                postData.Close();
                HttpWebResponse webResp = (HttpWebResponse)request.GetResponse();
                StreamReader loResponseStream = new StreamReader(webResp.GetResponseStream());
                string HelpResponse = loResponseStream.ReadToEnd();
                //// Then grab the content of the desired page ////////////////////////
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://www.ligatestowanba.ligspace.pl/index.php?pa=Admin&mod=AdminCms&ac=ExportData&download=teams");
                req.CookieContainer = cookies;
                req.Method = "GET";
                HttpWebResponse res = (HttpWebResponse)req.GetResponse();
                Stream resStream = res.GetResponseStream();
                StreamReader reader = new StreamReader(resStream);
                string input = reader.ReadToEnd();

7 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Sunny  Sharma
    0
    Hi Lukasz,

    Your code is working like a charm, I tested. It gives me the XML string that you mentioned . what error you're getting?
    0
  • 0
    my input string looks that: (the same as HelpResponse - string) - why??

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    Serwis dziala na platformie
    • Rejestracja
    • Logowanie

    •  


      • Start
      • Terminarz/wyniki
        • Klasyfikacja
          • Statystyki
            • Zespoly
              • Informacje
                 
                • Newsy
                • Regulamin
                • Linki
                • Download
                • Kontakt
                • Forum
                   
                   
                  LOGOWANIE DO SYSTEMU
                  Identyfikator:
                  Haslo:

                  Nie pamietam hasla

                  Nie masz jeszcze konta w systemie?

                  Kliknij tutaj i zalóz swój profil!

                  0
                • Sunny  Sharma
                  0
                  see what I'm using:
                  --------------------------------------------------------
                  static void Main(string[] args)  
                    {  

                        CookieContainer cookies = new CookieContainer();
                            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://www.ligatestowanba.ligspace.pl/index.php?pa=Admin&mod=Users&ac=Login";);  
                        request.Method = "POST";  request.CookieContainer = cookies;
                       string loginData = String.Format("username=testtest&password=awdsa");
                       request.ContentType = "application/x-www-form-urlencoded";
                       byte[] loginDataBytes = Encoding.ASCII.GetBytes(loginData);
                      Stream postData = request.GetRequestStream();
                      postData.Write(loginDataBytes, 0, loginDataBytes.Length);  postData.Close();
                      HttpWebResponse webResp = (HttpWebResponse)request.GetResponse();
                      StreamReader loResponseStream = new StreamReader(webResp.GetResponseStream());
                     string HelpResponse = loResponseStream.ReadToEnd();  
                   HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://www.ligatestowanba.ligspace.pl/index.php?pa=Admin&mod=AdminCms&ac=ExportData&download=teams";);
                     req.CookieContainer = cookies;  req.Method = "GET";  
                     HttpWebResponse res = (HttpWebResponse)req.GetResponse();
                     Stream resStream = res.GetResponseStream();
                    StreamReader reader = new StreamReader(resStream);  

                     string input = reader.ReadToEnd();  

                  Console.WriteLine(input);  

                  Console.ReadLine();

                  }

                  -------------------------------------------------------

                  and I get this in my console:
                  <? xml version = "1.0"?>
                  <teams/>
                  0
                • 0
                  with framework and VS do u use?? All time i've  the same input conten & I don't now why.....
                  0
                • Sunny  Sharma
                  0
                  I'm using Visual Studio 2010. .Net Framework 4.0.
                  0
                • 0
                  Upgrade to VS 2013 and the possibility of election framework 4.0 has solved the case. Unfortunately, my VS 2008 Express could not set a higher version than 3.5 framework

                  Which is better VS Express 2010, 2012 or 2013 when it comes to smooth operation?
                  0
                • 0
                  Hi,
                  I just tested.
                  If the target framework is less than 4.0 then it is not returning the xml file.
                  I'm using SharpDevelop IDE with .net Fx 4.0 and it is working fine.
                  You can try with SharpDevelop also but it does not have all the features of Visual Studio. 
                  0