Click here to Skip to main content
15,923,164 members
Home / Discussions / C#
   

C#

 
AnswerRe: Custom Tooltips in C# Pin
Astro the Space Duck5-Oct-07 6:24
Astro the Space Duck5-Oct-07 6:24 
GeneralRe: Custom Tooltips in C# Pin
Astro the Space Duck5-Oct-07 7:06
Astro the Space Duck5-Oct-07 7:06 
QuestionTextbox C# Pin
OlieColie4-Oct-07 13:47
OlieColie4-Oct-07 13:47 
AnswerRe: Textbox C# Pin
Colin Angus Mackay4-Oct-07 14:06
Colin Angus Mackay4-Oct-07 14:06 
AnswerRe: Textbox C# Pin
Christian Graus4-Oct-07 14:37
protectorChristian Graus4-Oct-07 14:37 
AnswerRe: Textbox C# Pin
Anthony Mushrow4-Oct-07 14:52
professionalAnthony Mushrow4-Oct-07 14:52 
GeneralRe: Textbox C# Pin
PIEBALDconsult4-Oct-07 15:14
mvePIEBALDconsult4-Oct-07 15:14 
AnswerRe: Textbox C# Pin
Malcolm Smart4-Oct-07 20:53
Malcolm Smart4-Oct-07 20:53 
AnswerRe: Textbox C# Pin
taranjotk4-Oct-07 21:30
taranjotk4-Oct-07 21:30 
QuestionC# Textbox Pin
OlieColie4-Oct-07 13:34
OlieColie4-Oct-07 13:34 
AnswerRe: C# Textbox Pin
Luc Pattyn4-Oct-07 13:37
sitebuilderLuc Pattyn4-Oct-07 13:37 
AnswerRe: C# Textbox Pin
taranjotk4-Oct-07 21:32
taranjotk4-Oct-07 21:32 
Questionhelp me in using dataGrid in C# Pin
michaelqog4-Oct-07 13:19
michaelqog4-Oct-07 13:19 
QuestionC# Help please! Pin
humblepgmr4-Oct-07 13:00
humblepgmr4-Oct-07 13:00 
AnswerRe: C# Help please! Pin
Guffa4-Oct-07 13:12
Guffa4-Oct-07 13:12 
GeneralRe: C# Help please! Pin
Christian Graus4-Oct-07 14:41
protectorChristian Graus4-Oct-07 14:41 
GeneralRe: C# Help please! Pin
Anthony Mushrow4-Oct-07 14:57
professionalAnthony Mushrow4-Oct-07 14:57 
GeneralRe: C# Help please! Pin
Christian Graus4-Oct-07 15:17
protectorChristian Graus4-Oct-07 15:17 
GeneralRe: C# Help please! Pin
Anthony Mushrow4-Oct-07 15:23
professionalAnthony Mushrow4-Oct-07 15:23 
AnswerRe: C# Help please! Pin
Guffa4-Oct-07 19:52
Guffa4-Oct-07 19:52 
QuestionComplex Regular Expression Pin
Skippums4-Oct-07 12:37
Skippums4-Oct-07 12:37 
AnswerRe: Complex Regular Expression Pin
MidwestLimey5-Oct-07 5:18
professionalMidwestLimey5-Oct-07 5:18 
GeneralRe: Complex Regular Expression Pin
Skippums5-Oct-07 5:36
Skippums5-Oct-07 5:36 
GeneralRe: Complex Regular Expression Pin
MidwestLimey5-Oct-07 6:08
professionalMidwestLimey5-Oct-07 6:08 
QuestionDownload File From Website With Login Pin
redfish344-Oct-07 11:39
redfish344-Oct-07 11:39 
I am attempting to automate the downloading of a file from a website that requires user login. At this point i want to get clarification of the steps i need to follow to accomplish this. Currently i am doing the following (in pseudo code) without success:

--Make POST HttpWebRequest/HttpWebResponse of "Login.php" that posts login username and password;
--Get response cookie collection and put into CookieContainer variable;
--Make HttpWebRequest/HttpWebResponse of "Content.php"; assign CookieContainer variable to request;
--Get GetResponseStream of response and put HTML content into String;
--Parse HTML content for download link;
--Download link to disk;
--Process downloaded file....

With this code, the HTML retrieved from Content.php is for a webpage shown to users that have not loged on and so the download link is not shown. Below is test code for the above.

// ##################################################################

public void TEST()
{
// login
// forms authenticate
string loginUri = AppGlobal.LoginUrl;
string requestString = "username=" + AppGlobal.UserName + "&password=" + AppGlobal.Password + "&autologin=checked";
byte[] requestData = Encoding.UTF8.GetBytes(requestString);

HttpWebRequest request = null;
Stream stream = null;
HttpWebResponse response = null;

// set up request
_cookies = new CookieContainer();
request = (HttpWebRequest)WebRequest.Create(loginUri);
request.Proxy = null;
request.CookieContainer = _cookies;
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = requestData.Length;
// make form post
stream = request.GetRequestStream();
stream.Write(requestData, 0, requestData.Length);

// get response
response = (HttpWebResponse)request.GetResponse();

// update cookies
foreach (Cookie returnCookie in response.Cookies)
{
// debug help
Debug.WriteLine("COOKIE: " + returnCookie.Name + " = " + returnCookie.Value);

// compare new cookie with stored cookie
// update cookie container
bool cookieFound = false;
foreach (Cookie oldCookie in _cookies.GetCookies(new Uri(AppGlobal.CookieUrl)))
{
if (returnCookie.Name == oldCookie.Name)
{
oldCookie.Value = returnCookie.Value;
cookieFound = true;
}
}
if (cookieFound == false)
{
_cookies.Add(new Uri(AppGlobal.CookieUrl), returnCookie);
}
}

// get webpage
request = (HttpWebRequest)WebRequest.Create(new Uri(AppGlobal.StartUrl));
request.Proxy = null;
request.CookieContainer = _cookies;

// get response
// check link
response = (HttpWebResponse)request.GetResponse();
string statusCode = response.StatusCode.ToString();

if (statusCode == "OK")
{
// handle cookies
foreach(Cookie returnCookie in response.Cookies)
{
bool cookieFound = false;
foreach(Cookie oldCookie in _cookies.GetCookies(new Uri(AppGlobal.CookieUrl)))
{
if (returnCookie.Name == oldCookie.Name)
{
oldCookie.Value = returnCookie.Value;
cookieFound = true;
}
}
if (cookieFound == false)
{
_cookies.Add(returnCookie);
}
}

// handle redirection

// get link html
StreamReader reader = new StreamReader(response.GetResponseStream());
string content = reader.ReadToEnd();

// check for failed log in
int position = content.IndexOf("Please log in to download");
if (position > -1)
{
Debug.WriteLine("FAILED");
}
Debug.WriteLine(content);
}
}



General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.