Question attachment.php

Zexor

Well-known member
Joined
Nov 28, 2008
Messages
520
Programming Experience
3-5
how do i download a file from attachment.php?
 
on some site, doing my.computer.network.downloadfile on the attachment.php will just download another html file instead of the attachment file.
 
it looks like it downloaded the login page to retrieve the password before it redirecting to the download file. So all webbrowser downloaded was the login page html.
 
but i am already logged in. If i actually click the link, it will popup an ie window to download the file. If i try download the attachment.php directly in code, it will just download the html
 
The request you are making to download the file in code is unrelated to any other requests. You need to either provide credentials as part of the request or, if you want to make this request part of an existing session, you must provide a reference to that existing session. The server doesn't know who you are unless you tell it.

I've never had go the second option myself before so I'm not sure of all the details. You may be able to Headers property or you may have to use an HttpWebRequest instead and use the CookieContainer property.
 
ok i find that if i just navigate the webbrowser1 to the attachment.php address, it will popup a save box for me to save the actual file. But i rather there is a way to save the file directly without any interaction from me. I was using My.computer.network.downloadfile before. i assume the webrequest/cookiecontainer will just let me load the page not direct download to a dir.
 
you mean fill in the username and password in the downloadfile? it gets me the same result as putting nothing in the field. And if you mean something else, then i dont know how to do it.
 
Last edited:
Hmmm... as I said, I've never actually done this myself so I'm not sure of the details. I would have thought that credentials passed when downloading would be enough but, if not, then you'll need to use two HttpWebRequests. The first would be to login and the second would use a cookie from the first response to download the file in the same session. I know there are examples out there because I've seen them but I can't point you to anything specific.
 
I dont know how to do what you said on the last post. But it seems to work if i just do a browser navigate to the download address instead of doing downloadfile, but a prompt popup asking for me to save. How do i make ie not to ask me to save and auto save to the default dir?
 
It works with a WebBrowser because it uses a cookie from the first request when making the second request, which is exactly what I suggested you do in my previous post. It is absolutely the wrong option to use a WebBrowser. It is a UI element and you don;t want the user to interface with this operation, obviously. The WebRequest class exists so that you can do this sort of thing without user interaction. If you don't know how to do something then you learn. Have you researched using a WebRequest? If you search properly then I know you'll find information because, as I said, I've seen it before myself. The first order of business should be to read the documentation for the WebRequest, HttpWebRequest and HttpWebResponse classes.
 
well i could use the webrequest to get to the first login page but i havent figure out how to login and get the cookie yet. it has a <form name="login" method="post" action="logging.php?action=login"></form> with login, password and a submit button.
 
Back
Top