|
Hello, I am fairly new to ASP.NET (C#)
I am looking for a way to call a web page and see what it returns.
For example call the page, http://www.page.com/login?accountname=me+password=you
if that page returns an error the function returns false if the page does not return an error the
function returns true.
I have been looking into using HTTPResponse and WebRequest but have not been successful at all.
Anyone have any thoughts on this?
Thanks,
~DE2
|
|
|
OK This is how I got it working:
XmlDataDocument mydata = new XmlDataDocument();
protected bool isauthenticated(string username, string password)
{
bool do_it = false;
try
{
mydata.DataSet.ReadXml("http://page.com/logonUser?userName=" + username + "&password=" + password);
}
catch (Exception e)
{
if (e.Message.ToString() == "The remote server returned an error: (500) Internal Server Error.")
{
do_it = false;
}
else
{
do_it = true;
}
}
return do_it;
}
I know that if that error message is returned the the login faild. So I set do_it to false.
??This seems to work??
|
|
|
The page that you are trying to access is not very secure if the poassword is passed in via the query string.
Anyway, you would not wan to use the xml unless the page you are trying to recieve is an xml document, or if it is a well formed XHTML document. Otherwise you would get an error in your read xml.
What you are looking to do is use the WebRequest method wich allows you to pass parameters with the request.
Of course if you are using only the querystring the webclient would suffice.
JB
|
|
|
|
|
|
|
|