Solved

Download from URL on a proxy Server

Posted on 2016-08-30
3
43 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

786 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