Clear DayHello,
I have implemented a download manger in .NET that overrides Internet
Explorer's bult-in download manager.
I using HttpWebRequest/Response to download the files.
All is working well except when I try to download an attachment file from a
web-based mailbox.
I've tried using credentials and saving the cookies, nothing helps.
Please try and assist me in this matter.
Tomer. 14 2942
tomer wrote: Clear DayHello,
I have implemented a download manger in .NET that overrides Internet Explorer's bult-in download manager.
I using HttpWebRequest/Response to download the files. All is working well except when I try to download an attachment file from a web-based mailbox.
I've tried using credentials and saving the cookies, nothing helps.
Well, post some code and describe the problem in more detail...
Cheers,
--
Joerg Jooss jo*********@gmx.net
Well,
The URL to resolve is something like this: http://some.domain.com/?w=/@attach&f...=Brusselse.wmv
HttpWebRequest request;
request = (HttpWebRequest)HttpWebRequest.Create(url);
request.AllowAutoRedirect=false;
request.Method = "GET";
CredentialCache wrCache = new CredentialCache();
wrCache.Add(new Uri(url),"Basic",new NetworkCredential(username,password));
request.Credentials = wrCache;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string newurl = GetRedirectURL(response); // it goes trough one
redirection, this function gets the new URL
Than I again do "request/response" with new url, and end up downloading HTML
page source code of some unknown page in the domain. (Maybe the logon page).
"Joerg Jooss" <jo*********@gmx.net> wrote in message
news:uJ*************@TK2MSFTNGP12.phx.gbl... tomer wrote: Clear DayHello,
I have implemented a download manger in .NET that overrides Internet Explorer's bult-in download manager.
I using HttpWebRequest/Response to download the files. All is working well except when I try to download an attachment file from a web-based mailbox.
I've tried using credentials and saving the cookies, nothing helps.
Well, post some code and describe the problem in more detail...
Cheers,
-- Joerg Jooss jo*********@gmx.net
tomer wrote: Well,
The URL to resolve is something like this: http://some.domain.com/?w=/@attach&f...=Brusselse.wmv
HttpWebRequest request;
request = (HttpWebRequest)HttpWebRequest.Create(url);
request.AllowAutoRedirect=false;
Out of curiosity: Why do need to implement your own redirection handling?
request.Method = "GET";
CredentialCache wrCache = new CredentialCache();
wrCache.Add(new Uri(url),"Basic",new NetworkCredential(username,password)); request.Credentials = wrCache;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string newurl = GetRedirectURL(response); // it goes trough one redirection, this function gets the new URL
But what exactly happens at this point? Are you sure you're not losing your
credentials or a session cookie?
Cheers,
--
Joerg Jooss jo*********@gmx.net
Hi Joerg,
I'm applying credentials and all setting again on the second request..
As for the Redirection, auto-redirect sometimes causes error.
There are no cookies associated with the first request (tried
cookiecontainer also).
After I get the new URL, I do Request/Response again (no redirection this
time), response content-length is "-1" but that's acceptable regarding the
fact IE can't see the this file's size too.
when I try to download the file (Streamreader or Binarystream, makes no
difference), I get a 7 kb size file with HTML content inside of him, instead
of a 4 MB WMV file.
"Joerg Jooss" <jo*********@gmx.net> wrote in message
news:eD**************@TK2MSFTNGP15.phx.gbl... tomer wrote: Well,
The URL to resolve is something like this: http://some.domain.com/?w=/@attach&f...=Brusselse.wmv
HttpWebRequest request;
request = (HttpWebRequest)HttpWebRequest.Create(url);
request.AllowAutoRedirect=false;
Out of curiosity: Why do need to implement your own redirection handling?
request.Method = "GET";
CredentialCache wrCache = new CredentialCache();
wrCache.Add(new Uri(url),"Basic",new NetworkCredential(username,password)); request.Credentials = wrCache;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string newurl = GetRedirectURL(response); // it goes trough one redirection, this function gets the new URL
But what exactly happens at this point? Are you sure you're not losing your credentials or a session cookie?
Cheers,
-- Joerg Jooss jo*********@gmx.net
tomer wrote: Hi Joerg,
I'm applying credentials and all setting again on the second request.. As for the Redirection, auto-redirect sometimes causes error.
Hm -- not that I wrote that part of the FCL, but I would be interested to
learn more about that error.
There are no cookies associated with the first request (tried cookiecontainer also).
So you passed in an empty CookieContainer, but HttpWebResponse.Cookies came
back empty?
After I get the new URL, I do Request/Response again (no redirection this time), response content-length is "-1" but that's acceptable regarding the fact IE can't see the this file's size too.
Are you using HTTP 1.1 or HTTP 1.0? Returning no Content-Length is only
allowed in certain circumstances.
when I try to download the file (Streamreader or Binarystream, makes no difference), I get a 7 kb size file with HTML content inside of him, instead of a 4 MB WMV file.
You cannot download a binary file using StreamReader -- it's meant to read
character data. So what is the actual HTML you download? The page itself? An
error page? If you're getting HTML content (not even some binary junk), that
makes me wonder whether the download URL is correct.
Cheers,
--
Joerg Jooss jo*********@gmx.net
Well, I've made some adjustmnet to the code,
The HTML I was gettin' was probably the LOGIN page of the mailbox.
that was after Webrequest.method = "PROPFIND",
if I change it back to "GET", I get a "500 internal server error", my guess,
'cause of authentication problems.
b.t.w - allowautoredirect = true, gives the same results (in this case).
Thanks...
"Joerg Jooss" <jo*********@gmx.net> wrote in message
news:uX**************@tk2msftngp13.phx.gbl... tomer wrote: Hi Joerg,
I'm applying credentials and all setting again on the second request.. As for the Redirection, auto-redirect sometimes causes error.
Hm -- not that I wrote that part of the FCL, but I would be interested to learn more about that error.
There are no cookies associated with the first request (tried cookiecontainer also).
So you passed in an empty CookieContainer, but HttpWebResponse.Cookies came back empty?
After I get the new URL, I do Request/Response again (no redirection this time), response content-length is "-1" but that's acceptable regarding the fact IE can't see the this file's size too.
Are you using HTTP 1.1 or HTTP 1.0? Returning no Content-Length is only allowed in certain circumstances.
when I try to download the file (Streamreader or Binarystream, makes no difference), I get a 7 kb size file with HTML content inside of him, instead of a 4 MB WMV file.
You cannot download a binary file using StreamReader -- it's meant to read character data. So what is the actual HTML you download? The page itself? An error page? If you're getting HTML content (not even some binary junk), that makes me wonder whether the download URL is correct.
Cheers,
-- Joerg Jooss jo*********@gmx.net
tomer wrote: Well, I've made some adjustmnet to the code, The HTML I was gettin' was probably the LOGIN page of the mailbox. that was after Webrequest.method = "PROPFIND",
PROPFIND is a WebDAV method. Why would you want to use that?
Cheers,
--
Joerg Jooss jo*********@gmx.net
That was what I CHANGED, propfind was a mistake , I went back to GET.
Now I get "500 internal server error". if I change it back to "GET", I get a "500 internal server error", my guess, 'cause of authentication problems
Any thoughts?
"Joerg Jooss" <jo*********@gmx.net> wrote in message
news:%2****************@tk2msftngp13.phx.gbl... tomer wrote: Well, I've made some adjustmnet to the code, The HTML I was gettin' was probably the LOGIN page of the mailbox. that was after Webrequest.method = "PROPFIND",
PROPFIND is a WebDAV method. Why would you want to use that?
Cheers,
-- Joerg Jooss jo*********@gmx.net
tomer wrote: That was what I CHANGED, propfind was a mistake , I went back to GET. Now I get "500 internal server error".
if I change it back to "GET", I get a "500 internal server error", my guess, 'cause of authentication problems
Any thoughts?
Use a local proxy like Fiddler ( www.fiddlertool.com) to record a complete
web conversation with the web application to better understand how it works.
You obviously broke something with that GET request ;-)
Cheers,
--
Joerg Jooss jo*********@gmx.net
Joerg,
Thanks for the tip, it turned out to be rather useful.
I managed to see what's the difference between my request and IE's request.
I turns out that IE sends the request with a cookie, which I can't seem to
find anywhere, guess it's the login cookie...
If I copy the cookie from fiddler's IE request and send my request with it,
it all goes well.
Now I only need to find a way to get this cookie.
D'you know any method of extracting cookies out of pages? am I even in the
right direction?
Thanks alot for your time,
Tomer.
"Joerg Jooss" <jo*********@gmx.net> wrote in message
news:Ow**************@TK2MSFTNGP15.phx.gbl... tomer wrote: That was what I CHANGED, propfind was a mistake , I went back to GET. Now I get "500 internal server error".
if I change it back to "GET", I get a "500 internal server error", my guess, 'cause of authentication problems
Any thoughts?
Use a local proxy like Fiddler (www.fiddlertool.com) to record a complete web conversation with the web application to better understand how it works. You obviously broke something with that GET request ;-)
Cheers,
-- Joerg Jooss jo*********@gmx.net
tomer wrote: Joerg,
Thanks for the tip, it turned out to be rather useful. I managed to see what's the difference between my request and IE's request. I turns out that IE sends the request with a cookie, which I can't seem to find anywhere, guess it's the login cookie... If I copy the cookie from fiddler's IE request and send my request with it, it all goes well. Now I only need to find a way to get this cookie. D'you know any method of extracting cookies out of pages? am I even in the right direction?
That's why I asked whether you're using an empty CookieContainer with your
initial request ;-)
You have to create an CookieContainer for your request, otherwise there will
be no cookies in the response:
HttpWebRequest firstRequest = (HttpWebRequest) WebRequest.Create(url);
firstRequest.CookieContainer = new CookieContainer();
HttpWebResponse firstResponse = (HttpWebResponse)
firstRequest.GetResponse();
HttpWebRequest secondRequest = (HttpWebRequest) WebRequest.Create(url);
secondRequest.CookieContainer = new CookieContainer();
CookieCollection cookies = firstResponse.Cookies;
secondRequest.CookieContainer.Add(cookies);
Cheers,
--
Joerg Jooss jo*********@gmx.net
Hi Joerg,
I tried before using the cookie container.
It returned empty.
The problem is, the cookie dosen't return with the response, it has to be
SENT with the request in order to even get a proper response.
I believe this cookie is stored in the cookies directories, so all I need is
to get the proper cookie for the domain from the directory, parse the cookie
file to a string and send it with the request.
Am I right?
Thanks, Tomer.
"Joerg Jooss" <jo*********@gmx.net> wrote in message
news:e4**************@TK2MSFTNGP09.phx.gbl... tomer wrote: Joerg,
Thanks for the tip, it turned out to be rather useful. I managed to see what's the difference between my request and IE's request. I turns out that IE sends the request with a cookie, which I can't seem to find anywhere, guess it's the login cookie... If I copy the cookie from fiddler's IE request and send my request with it, it all goes well. Now I only need to find a way to get this cookie. D'you know any method of extracting cookies out of pages? am I even in the right direction?
That's why I asked whether you're using an empty CookieContainer with your initial request ;-)
You have to create an CookieContainer for your request, otherwise there will be no cookies in the response:
HttpWebRequest firstRequest = (HttpWebRequest) WebRequest.Create(url); firstRequest.CookieContainer = new CookieContainer(); HttpWebResponse firstResponse = (HttpWebResponse) firstRequest.GetResponse();
HttpWebRequest secondRequest = (HttpWebRequest) WebRequest.Create(url); secondRequest.CookieContainer = new CookieContainer(); CookieCollection cookies = firstResponse.Cookies; secondRequest.CookieContainer.Add(cookies);
Cheers,
-- Joerg Jooss jo*********@gmx.net
tomer wrote: Hi Joerg,
I tried before using the cookie container. It returned empty. The problem is, the cookie dosen't return with the response, it has to be SENT with the request in order to even get a proper response.
You have to receive the cookie first before you can submit it again with
another request, don't you?
You *must* use a CookieContainer with the very first request you send,
assuming that's the one that authenticates you.
I believe this cookie is stored in the cookies directories, so all I need is to get the proper cookie for the domain from the directory, parse the cookie file to a string and send it with the request. Am I right?
Yes, if it is a persistent cookie. But you'll have to use Win32 APIs to read
the cookie.
See http://msdn.microsoft.com/library/de...tgetcookie.asp
Cheers,
--
Joerg Jooss jo*********@gmx.net
Hi Joerg,
The request I send is the first (because I get the download url only, from
IE after IE logged in to site).
Anyhow, the cookie is a permanent cookie so I need to read it from the
cookies directory.
As for the InternetGetCookie API, looks like it does the trick quite nicely,
dosen't look like to much hassle to wrap it into .NET.
I'm pretty confident this will solve the whole issue..
Thank you for all your help!!!
Best Regards,
Tomer.
"Joerg Jooss" <jo*********@gmx.net> wrote in message
news:eH**************@TK2MSFTNGP10.phx.gbl... tomer wrote: Hi Joerg,
I tried before using the cookie container. It returned empty. The problem is, the cookie dosen't return with the response, it has to be SENT with the request in order to even get a proper response.
You have to receive the cookie first before you can submit it again with another request, don't you?
You *must* use a CookieContainer with the very first request you send, assuming that's the one that authenticates you.
I believe this cookie is stored in the cookies directories, so all I need is to get the proper cookie for the domain from the directory, parse the cookie file to a string and send it with the request. Am I right?
Yes, if it is a persistent cookie. But you'll have to use Win32 APIs to read the cookie. See http://msdn.microsoft.com/library/de...tgetcookie.asp
Cheers,
-- Joerg Jooss jo*********@gmx.net
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: TJO |
last post by:
Can someone at MS please reply to this. I am trying to post data so a web
form via ssl with the following code. I keep getting this error: "The
underlying connection was closed: Could not...
|
by: Kueishiong Tu |
last post by:
I have a url, I pass it to Webclient, and I get response without any problem.
String* uriString = S"trade7.masterlink.com.tw/futures/QuotePrice.jsp";
String* postData = S"";
// Create a new...
|
by: thomas peter |
last post by:
I am building a precache engine... one that request over 100 pages on an
remote server to cache them remotely...
can i use the HttpWebRequest and WebResponse classes for this? or must i use
the...
|
by: Sivashankaran Vaidhyalingam |
last post by:
Hi folks,
I have an aspx application App A hosted in a server which is inside
the intranet . I need to serve pages from this application _through_
another application App B which acts as a proxy...
|
by: iana_kosio |
last post by:
Hi,
I am using HttpWebRequest class to communicate with remote server. In some cases the server would return 5xx status code which results in HttpWebRequest object throwing an exception. I,...
|
by: sfoxover |
last post by:
Hi,
Could someone please give me some suggestions on how to make this class
robust. I need to be able to handle around 20 similtanious requests to
this class which causes a web browser to...
|
by: Oliver |
last post by:
I have a very wired problem requesting one specific url from within my
application.
I have struggeled with this for 5 hours now, and searched google withour any
luck, so i hope that someone are...
|
by: Fred Herring |
last post by:
I currently use httpwebrequest to download large byte array files from my
server. I am curious about how to change my httpwebrequest code to allow
posing a large byte array to a virtual foldeer. ...
|
by: boxboy |
last post by:
Hi, I'm writing a console application and am having a problem with HttpWebRequest
when posting data to a webserver. A "System.Net.WebException: The server committed a
protocol violation" is always...
|
by: dattaforit |
last post by:
I am using VC++ .Net (2003). In my application i create a HttpWebRequest object, add the method and header to the request. An now try to get the response. I get the response. to get the response i...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |