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:
I go to the website: http://www.ligatestowanba.ligspace.pl/index.php?pa=Admin&mod=Users&ac=Login
Logs:
Username: testtest
password: awdsa
Then, on a static link to the xml file that wants to download: http://www.ligatestowanba.ligspace.pl/index.php?pa=Admin&mod=AdminCms&ac=ExportData&download=teams
contents of the file should be this:
xml version = "1.0"?>
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();
//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();
Posted Jul 26, 2013, 1:51 PM
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.
Lukasz GrygielPosted Jul 26, 2013, 9:08 AM
Sunny SharmaPosted Jul 26, 2013, 8:03 AM
Lukasz GrygielPosted Jul 26, 2013, 7:59 AM
Sunny SharmaPosted Jul 26, 2013, 7:38 AM
--------------------------------------------------------
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"?>
Lukasz GrygielPosted Jul 26, 2013, 6:33 AM
LOGOWANIE DO SYSTEMU
Nie pamietam hasla
Nie masz jeszcze konta w systemie?
Kliknij tutaj i zalóz swój profil!
Sunny SharmaPosted Jul 26, 2013, 6:12 AM
Your code is working like a charm, I tested. It gives me the XML string that you mentioned . what error you're getting?