"The remote server returned an error: (407) Proxy Authentication Required" при скачивании файла

Рейтинг: 0Ответов: 1Опубликовано: 27.03.2015

Добрый день!

Есть код (взят мною с MSDN):

string remoteUri = downloadFrom.Replace(fileName, "");
string myStringWebResource = null;
// Create a new WebClient instance.
WebClient myWebClient = new WebClient();
// Concatenate the domain with the Web resource filename.
myStringWebResource = remoteUri + fileName;
Console.WriteLine("Downloading File \"{0}\" from \"{1}\" .......\n\n", fileName, myStringWebResource);
// Download the Web resource and save it into the current filesystem folder.
myWebClient.DownloadFile(myStringWebResource, fileName);
Console.WriteLine("Successfully Downloaded File \"{0}\" from \"{1}\"", fileName, myStringWebResource);
Console.WriteLine("\nDownloaded file saved in the following file system folder:\n\t" + fileDestination);

Грубо говоря, я скачиваю файл. На строчке myWebClient.DownloadFile вылетает ошибка:

The remote server returned an error: (407) Proxy Authentication Required.

Подскажите, пожалуйста, как ее можно обойти?

UPDATE

Качаю файл с сайта ООН.

UPDATE2

После того как прописал в App.config:

<system.net>
    <defaultProxy useDefaultCredentials="true" >
    </defaultProxy>
</system.net>

Скачивания якобы идет какое-то время, ошибок нету, но при этом в результирующей папке пусто. (

Подскажите, пожалуйста, где я ошибся?

Ответы

▲ 2Принят

Добавьте в конфиг-файл своего проекта следующую запись:

<system.net>
    <defaultProxy useDefaultCredentials="true" >
    </defaultProxy>
</system.net>