o0JoeCool0o1
asked on
Invalid URI: The format of the URI could not be determined.
Trying to create a system.net.webrequest which takes a uri as the parameter I want to pass in a relative path for example "mypage.htm" which should grab the path form the current directory
I am calling iswellformed which is passing true from the system.uri class howeveri still recieve the error
Invalid URI: The format of the URI could not be determined.
how do i use a relative path as the uri ?
I am calling iswellformed which is passing true from the system.uri class howeveri still recieve the error
Invalid URI: The format of the URI could not be determined.
how do i use a relative path as the uri ?
HttpContext.Current.Reques t.Applicat ionPath should get the current application path to which you can add the relative path at run time
ASKER
Dim uri As New System.Uri(HttpContext.Cur rent.Reque st.Applica tionPath & "/" & url)
returns the same error
url = "mypage.html"
returns the same error
url = "mypage.html"
I am still not exactly sure what you are trying to do, but maybe this will work:
Dim uri As New Uri("file://" & Request.MapPath("mypage.ht m"))
Bob
Dim uri As New Uri("file://" & Request.MapPath("mypage.ht
Bob
ASKER
I am getting html from a page
the page is passed via querystring on the calling funciton and i dont want to pass a full absolute web path.
I just want to pass "Thepage.htm" because it lies in the same directory as the .net page
Public Function getPageHTML(ByVal url As String) As String
If System.Uri.IsWellFormedUri String(url , UriKind.Relative) Then
Dim uri As New System.Uri(HttpContext.Cur rent.Reque st.Applica tionPath & "/" & url)
Dim request As HttpWebRequest = WebRequest.Create(uri)
'Set some reasonable limits on resources used by this request
request.MaximumAutomaticRe directions = 4
request.MaximumResponseHea dersLength = 4
'Set credentials to use for this request.
request.Credentials = CredentialCache.DefaultCre dentials
Dim response As HttpWebResponse = request.GetResponse()
'Get the stream associated with the response.
Dim receiveStream As Stream = response.GetResponseStream ()
'Pipes the stream to a higher level stream reader with the required encoding format.
Dim readStream As StreamReader = New StreamReader(receiveStream , Encoding.UTF8)
Dim strResponse As String = readStream.ReadToEnd()
response.Close()
readStream.Close()
Return strResponse
Else
Return Nothing
End If
End Function
the page is passed via querystring on the calling funciton and i dont want to pass a full absolute web path.
I just want to pass "Thepage.htm" because it lies in the same directory as the .net page
Public Function getPageHTML(ByVal url As String) As String
If System.Uri.IsWellFormedUri
Dim uri As New System.Uri(HttpContext.Cur
Dim request As HttpWebRequest = WebRequest.Create(uri)
'Set some reasonable limits on resources used by this request
request.MaximumAutomaticRe
request.MaximumResponseHea
'Set credentials to use for this request.
request.Credentials = CredentialCache.DefaultCre
Dim response As HttpWebResponse = request.GetResponse()
'Get the stream associated with the response.
Dim receiveStream As Stream = response.GetResponseStream
'Pipes the stream to a higher level stream reader with the required encoding format.
Dim readStream As StreamReader = New StreamReader(receiveStream
Dim strResponse As String = readStream.ReadToEnd()
response.Close()
readStream.Close()
Return strResponse
Else
Return Nothing
End If
End Function
Did you try this?
Dim uri As New Uri("file://" & Server.MapPath("mypage.htm "))
Bob
Dim uri As New Uri("file://" & Server.MapPath("mypage.htm
Bob
ASKER
that gives the error
Unable to cast object of type 'System.Net.FileWebRequest ' to type 'System.Net.HttpWebRequest '.
Unable to cast object of type 'System.Net.FileWebRequest
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
that worked! Thanks!
Have similar issue on our Verio-Hosted site. Used to work - using below function to retrieve html-text (of an aspx page to email content as a summary/confirmation)
Protected Function HttpContent(ByVal url As String) As String
Dim objRequest As WebRequest = System.Net.HttpWebRequest. Create(url )
Dim sr As New StreamReader(objRequest.Ge tResponse( ).GetRespo nseStream( ))
Dim result As String = sr.ReadToEnd()
sr.Close()
Return result
End Function
Believe security or service pack updates have altered default-behaviour on
System.Net.HttpWebRequest. Create(url ) - call / same-or similar to the above referenced URI -webrequest create...
I changed our code to adapt above solution - unfortunately the usage of the fully qualified path is prohibit on Verio's share webserver and usage results in an Internal-Server-500 error. without the path same result as in my original function - Invalid URI: The format of the URI could not be determined
Does anyone have any other advice?
Protected Function HttpContent(ByVal url As String) As String
Dim objRequest As WebRequest = System.Net.HttpWebRequest.
Dim sr As New StreamReader(objRequest.Ge
Dim result As String = sr.ReadToEnd()
sr.Close()
Return result
End Function
Believe security or service pack updates have altered default-behaviour on
System.Net.HttpWebRequest.
I changed our code to adapt above solution - unfortunately the usage of the fully qualified path is prohibit on Verio's share webserver and usage results in an Internal-Server-500 error. without the path same result as in my original function - Invalid URI: The format of the URI could not be determined
Does anyone have any other advice?