gani7787 Ответов: 1

Формат URI не поддерживается.удаленный сервер вернул ошибку: (401) unauthorized.


Hi,

I want to download the document from below mentioned URL. When i try to download directly in the IE URL, it will be asking username and password credential to open the document.

But, when i try to download through application i am getting below error.

"The remote server returned an error: (401) Unauthorized."

ASP.NET Code:

downloadbutton_click event

URIFile = http://sr1250kl.vrmnet.vrm.intranet/A1/servlet/Download?auth=basic&event_name=k1_view&_file=emparea&id=0000008763&version=01

Dim client As New WebClient()
client.Credentials = CredentialCache.DefaultCredentials
client.UseDefaultCredentials = True
client.Credentials = New NetworkCredential("XXXXXX", "XXXXXXX", "vrmnet.vrm.intranet")
Dim buffer As Byte() = client.DownloadData(URIFile )
Dim download As String = Encoding.ASCII.GetString(buffer)
Console.WriteLine(download)
Console.WriteLine("Download successful.")
Response.ContentType = "application/pdf"
Response.AddHeader("content-length", buffer.Length.ToString())
Response.BinaryWrite(buffer)

The above code is not working when i click the download button using above code. Error : "The remote server returned an error: (401) Unauthorized."

How to download the file..?


Что я уже пробовал:

URIFile = http://sr1250kl.vrmnet.vrm.intranet/A1/servlet/Download?auth=basic&event_name=k1_view&_file=emparea&id=0000008763&version=01

Дим клиента в качестве нового веб-клиента()
клиент.Учетные Данные = CredentialCache.Свойство defaultcredentials
клиент.UseDefaultCredentials = True
клиент.Учетные данные = новый а networkcredential("ХХХХХХ", "ХХХХХХХ", "vrmnet.ВРМ.интранет")
Dim buffer As Byte () = клиент.DownloadData(URIFile )
Dim download As String = Encoding.ASCII.GetString(буфер)
Приставка.WriteLine(скачать)
Приставка.WriteLine ("загрузка прошла успешно.")
Ответ.ContentType = " приложение / pdf"
Ответ.AddHeader ("content-length", buffer.Длина.Метод toString())
Ответ.BinaryWrite(буфер)

gani7787

Любое решение для этого...жду ответа от кого угодно...

1 Ответов

Рейтинг:
0

gani7787

Finally i did R&D i found the solution.it's very simple code.

Dim fileName As String = grd.DataKeys(gvrow.RowIndex).Values(0).ToString()

ScriptManager.RegisterStartupScript(Me, Page.GetType(), "Open", "window.open('" + fileName + "');", True)