Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing webmail inbox

Status
Not open for further replies.

Craftor

Programmer
Feb 1, 2001
420
0
0
NZ
Hi all

I need to be able to parse an Outlook Inbox that is only accessable via Webmail i.e. I enter a URL ([ignore][/ignore]) and am prompted for my username and passsword.

I've been trying to even just get a screenscrape of the page returned using the System.Net.HttpWebRequest object but it is refusing to authenticate me.

I have tried using Network Credentials to pass my username and password and I have tried to add an Authorization HTTP Header but the connection is refused on both tries.

The code is as follows:

Network Credentials Method
Code:
string requestURI = "[URL unfurl="true"]http://myserver/exchange/myuser/inbox";[/URL]
System.Net.HttpWebRequest wr = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(requestURI);
wr.PreAuthenticate = true;
NetworkCredential credential = new NetworkCredential("myuser","mypassword","mydomain");
wr.Credentials = credential;
System.IO.StreamReader responseReader = new System.IO.StreamReader(wr.GetResponse().GetResponseStream());

string response = responseReader.ReadToEnd();

Http Headers Method
Code:
string requestURI = "[URL unfurl="true"]http://myserver/exchange/myuser/inbox";[/URL]
System.Net.HttpWebRequest wr = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(requestURI);
wr.Headers.Add("Authorization:myuser:mypassword");
System.IO.StreamReader responseReader = new System.IO.StreamReader(wr.GetResponse().GetResponseStream());
string response = responseReader.ReadToEnd();

Both of these methods fail on the wr.GetResponse().GetResponseStream()) call.

Can anyone help me with what I am doing wrong or possibly suggest a better way to do this, please?

Thanks as always


Craftor
:cool:
 
How are you prompted for username and password? Is this trough a form, http authentication box or maybe some other method?

And then silence smacks right in there...
... And it is loud!
 
Hi xai999

Managed to overcome this one, thanks, by using the CredentialCache object as opposed to creating a NetworkCredential object.

Ciao


Craftor
:cool:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top