Click here to Skip to main content
15,881,413 members
Home / Discussions / C#
   

C#

 
QuestionDownloading pdf while creating in a loop Pin
tauras8129-May-09 5:35
tauras8129-May-09 5:35 
AnswerRe: Downloading pdf while creating in a loop Pin
EliottA29-May-09 5:53
EliottA29-May-09 5:53 
GeneralRe: Downloading pdf while creating in a loop Pin
Henry Minute29-May-09 5:57
Henry Minute29-May-09 5:57 
AnswerRe: Downloading pdf while creating in a loop Pin
Luc Pattyn29-May-09 6:11
sitebuilderLuc Pattyn29-May-09 6:11 
GeneralRe: Downloading pdf while creating in a loop Pin
EliottA29-May-09 6:15
EliottA29-May-09 6:15 
GeneralRe: Downloading pdf while creating in a loop Pin
Luc Pattyn29-May-09 6:31
sitebuilderLuc Pattyn29-May-09 6:31 
AnswerRe: Downloading pdf while creating in a loop Pin
Uffe Rask29-May-09 11:24
Uffe Rask29-May-09 11:24 
QuestionBumping an old post - https web request [modified] Pin
Mike Devenney29-May-09 5:27
Mike Devenney29-May-09 5:27 
I'm still trying to get a block of code that does an https file download working. The vendor (swift.com) says that they took my code and got it working on their end no problem which leads me to believe that the something that is preventing me lives on my side of the request. We have a download scanner that pops up when I load the URL in my browser, so it's possible that I'm getting blocked there but I'm still working with the security team on that one. I'd appreciate it if someone could take a look at my code below and let me know if you see anything that's wrong/missing/poorly formed for an https request. This is being run from a .NET 2.0 console application if that makes any difference. I highlighted the line in the code where the 401 Unauthorized error occurs.

I added a few hard returns to the code to keep the page from going WAY WIDE. If you pull the code down from here and past it into VS you might have to remove them.
private bool DownloadFile()
        {
            private const string URL = "https://www2.swift.com/bicdownload/bicdownloader?
action=getfile&productline=bicdir&product=bicdb&content=full&format=txt&platform=win";
            try
            {
                string bicFileTemp = string.Format("{0}\\BIC-{1}.txt", 
ConfigurationManager.AppSettings["BICDLPath"], DateTime.Now.ToString("dd-MMM-yyyy"));
                string line;


                // build credentials for SWIFT authentication
                System.Net.NetworkCredential cred = new System.Net.NetworkCredential();
                cred.UserName = "myUserName";
                cred.Password = "myPassword";
                WebRequest myReq = WebRequest.Create(URL);
                myReq.Credentials = cred;


                // build credentials for WTC Proxy authentication
                myReq.Proxy = WebProxy.GetDefaultProxy();
                myReq.Proxy.Credentials = CredentialCache.DefaultCredentials;


                // send request and get response
* ERROR HERE *  WebResponse wr = myReq.GetResponse();
                Stream receiveStream = wr.GetResponseStream();
                StreamReader sr = new StreamReader(receiveStream, Encoding.UTF8);
                StringBuilder bicFile = new StringBuilder();


                // parse response into file, write file out to \\server\BICDownloads
                do
                {
                    line = sr.ReadLine();
                    bicFile.Append(line);

                } while (line != null);

                File.WriteAllText(bicFileTemp, bicFile.ToString());

                return true;
            }
            catch (Exception ex)
            {
                Utilities.ReportError("Error in BIC-DownloadFile: " + ex.Message, this, ex.StackTrace);
                return false;
            }
        }


Mike Devenney

modified on Friday, May 29, 2009 11:35 AM

AnswerRe: Bumping an old post - https web request Pin
Nicholas Butler29-May-09 7:13
sitebuilderNicholas Butler29-May-09 7:13 
GeneralRe: Bumping an old post - https web request Pin
Mike Devenney29-May-09 7:16
Mike Devenney29-May-09 7:16 
GeneralRe: Bumping an old post - https web request Pin
Nicholas Butler29-May-09 7:24
sitebuilderNicholas Butler29-May-09 7:24 
GeneralRe: Bumping an old post - https web request Pin
Mike Devenney3-Jun-09 3:54
Mike Devenney3-Jun-09 3:54 
GeneralRe: Bumping an old post - https web request Pin
Nicholas Butler3-Jun-09 4:38
sitebuilderNicholas Butler3-Jun-09 4:38 
GeneralRe: Bumping an old post - https web request Pin
Mike Devenney3-Jun-09 6:57
Mike Devenney3-Jun-09 6:57 
GeneralRe: Bumping an old post - https web request Pin
Nicholas Butler3-Jun-09 7:29
sitebuilderNicholas Butler3-Jun-09 7:29 
GeneralRe: Bumping an old post - https web request Pin
Mike Devenney3-Jun-09 7:34
Mike Devenney3-Jun-09 7:34 
GeneralRe: Bumping an old post - https web request Pin
Nicholas Butler3-Jun-09 11:32
sitebuilderNicholas Butler3-Jun-09 11:32 
GeneralRe: Bumping an old post - https web request Pin
Mike Devenney4-Jun-09 2:33
Mike Devenney4-Jun-09 2:33 
GeneralRe: Bumping an old post - https web request Pin
Mike Devenney4-Jun-09 7:32
Mike Devenney4-Jun-09 7:32 
QuestionCreate buttons dinamyclly Pin
geniaz129-May-09 5:03
geniaz129-May-09 5:03 
GeneralRe: Create buttons dinamyclly Pin
musefan29-May-09 5:08
musefan29-May-09 5:08 
AnswerRe: Create buttons dinamyclly Pin
EliottA29-May-09 5:20
EliottA29-May-09 5:20 
GeneralRe: Create buttons dinamyclly Pin
geniaz129-May-09 5:51
geniaz129-May-09 5:51 
GeneralRe: Create buttons dinamyclly Pin
Douglas Kirk29-May-09 7:08
Douglas Kirk29-May-09 7:08 
GeneralRe: Create buttons dinamyclly Pin
Moreno Airoldi29-May-09 7:15
Moreno Airoldi29-May-09 7:15 

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.