Skip to main content
Home Forums Silverlight Programming Report a Silverlight Bug HttpWebRequest does not escape uri
7 replies. Latest Post by vijaydevatha on November 24, 2008.
(0)
Eloff
Member
139 points
114 Posts
04-28-2008 12:58 PM |
Take an escaped (url encoded) uri, pass it into System.Uri.
>>> from System import Uri >>> u = Uri('http://foo.com/?equals=%3d') >>> u.ToString() 'http://foo.com/?equals=='
It gets unescaped, and this seems normal .NET behavior. But HttpWebRequest actually will try to fetch the unescpaed uri (which won't work correctly in this case and many others.)
A temporary workaround is to double UrlEncode the uri before passing it to System.Uri. But I think this must indicate a bug in HttpWebRequest.
Allen Ch...
Star
13856 points
1,800 Posts
04-30-2008 1:57 AM |
Hi:
Have you tried this overload method to initialize the uri?
Uri(string uriString,bool dontEscape)
Regards
mscherotter
119 points
21 Posts
05-23-2008 3:25 PM |
Allen,
You suggested an overload that isn' t in the SL2 System.Uri class. In .Net, that API is no obsoled: http://msdn.microsoft.com/en-us/library/9zh9wcb3.aspx
I have run into this problem as well as the web service that I am working with expects escaped information in the URI.
Michael
silverli...
41 points
25 Posts
06-04-2008 11:53 AM |
This really drives me crazy. I have to pass some variables in the querystring and it’s not working every time, even if I double escape the values. Is there a solution?
ssawchenko
342 points
176 Posts
11-19-2008 12:48 PM |
Was a solution ever found for this? I have bumped into a similar issue.
11-19-2008 12:54 PM |
double-encoding or triple-encoding was my solution.
11-20-2008 2:25 AM |
My solution was more a workaround, sending the parameters in a xml string with the request.
Dim _Page As Page = App.Current.RootVisual
Dim _Request As New HttpHelper(_Page.GetApplicationURL & "Test.aspx", Me.Dispatcher) _Request.Method = "POST" _Request.ContentType = "text/xml"
_Request.RequestText = "<?xml version='1.0'?>" & _ "<Daten>" & _ "<ID>" + ReplaceSign(Path) + "</ID>" & _ "</Daten>"
AddHandler _Request.RequestReady, AddressOf Me.TestCallBack _Request.Execute()
Private Function ReplaceSign(ByVal FeldWert As String) As String FeldWert = FeldWert.Replace("&", "&") FeldWert = FeldWert.Replace("<", "<") FeldWert = FeldWert.Replace(">", ">")
Return FeldWert End Function
On the server I read the input with this code:
Dim objXML As XmlDocument = New XmlDocument() objXML.Load(Request.InputStream)
Response.write(objXML.SelectSingleNode("Daten/ID").InnerText)
vijaydev...
111 points
11-24-2008 1:41 PM |
I'm not able to reproduce this issue, and the fact that so many of you seem to be hitting this is making me wonder if I understand the problem to begin with.
I tried issuing a GET to each of the following URLs using HttpWebRequest (I was testing eith IE7 on Vista, using SL2.0 RTW bits):
In each case, I found that the Uris were sent across the wire as-is; i.e., HttpWebRequest does no encoding/decoding/mangling of any kind. "%3d" was sent as "%3d", not as "=". Is that not what you're seeing or expecting?
Thanks!