URI格式不受支持。远程服务器返回错误:(401)未经授权。 [英] URI format not supported.the remote server returned an error: (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
Dim client As New WebClient()
client.Credentials = CredentialCache.DefaultCredentials
client.UseDefaultCredentials =真的
client.Credentials =新的NetworkCredential(XXXXXX,XXXXXXX,vrmnet.vrm.intranet)
Dim buffer As Byte()= client.DownloadData (URIFile)
昏暗下载As String = Encoding.ASCII.GetString(缓冲区)
Console.WriteLine(下载)
Console.WriteLine( 下载成功。)
回复。 ContentType =application / pdf
Response.AddHeader(content-length,buffer.Length.ToString())
Response.BinaryWrite(buffer)
What I have tried:
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)
推荐答案
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)
这篇关于URI格式不受支持。远程服务器返回错误:(401)未经授权。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!