Solved

Download from URL on a proxy Server

Posted on 2016-08-30
3
58 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 13

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Suggested Courses

740 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