Solved

Download from URL on a proxy Server

Posted on 2016-08-30
3
38 Views
Last Modified: 2016-08-31
The code below works on my local machine.  However to connect to external websites on the production server, I have to set the hostname to ftpProxy.

Example:

On the old server I would use these credentials.

set HOSTNAME=ftp.site.com
set USERID=user
set PWD=yyy

On the new server I would use these.

set HOSTNAME=ftpproxy
set USERID=user@ftp.site.com
set PWD=yyy

How do I get this to work on the production server?  I'm using a C# windows form program.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
namespace WebDownloader
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                WebClient client = new WebClient();
                string Webpage = client.DownloadString("https://www.Site.com/xmlfeed/xml_prices_full.asp?code=99201&user=xxxml&pass=yy");
                using (StreamWriter sw = new StreamWriter("O:\\Data_Download\\Supplier\\SupplierFile.txt"))
                {
                    sw.Write(Webpage);
                }
                Webpage = client.DownloadString("https://www.Site.com/xmlfeed/xml_prices_full.asp?code=99221&user=xxxml&pass=yy");
                using (StreamWriter sw = new StreamWriter("O:\\Data_Download\\Supplier\\SupplierFileMBIO.txt"))
                {
                    sw.Write(Webpage);
                }

                Environment.Exit(0);
            }
            catch (Exception ex)
            {
                using (StreamWriter sw2 = new StreamWriter("O:\\Loaders\\Global\\Supplier\\Commodities\\Price\\Errors\\DownloadError.txt"))
                {
                    sw2.Write(ex.Message);
                    
                }
                Environment.Exit(1);
            }
        }
    }
}

Open in new window

0
Comment
Question by:AlHal2
3 Comments
 
LVL 20

Accepted Solution

by:
Daniel Van Der Werken earned 250 total points
ID: 41776722
I recommend you trying this.

using System.Net;
            WebProxy webProxy = new WebProxy("http://10.1.1.1:8080");
            WebClient wClient = new WebClient();
            wClient.Proxy = webProxy;

Open in new window


Where http://10.1.1.1:8080 is the address of the proxy.

Then try to authenticate again the same way you are. You may have to try both ways.
1
 
LVL 12

Assisted Solution

by:Jeff Darling
Jeff Darling earned 250 total points
ID: 41776734
To supply the username/password for the proxy

                client.Proxy.Credentials = new NetworkCredential("myusername", "mypassword");
                client.Proxy.GetProxy(new Uri("proxy.server.com:8080"));

Open in new window

1
 

Author Closing Comment

by:AlHal2
ID: 41777665
Thank you.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

939 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now