WebClient encoding problems is vb.net
In my vb.net application I am interacting with a webservice written by another group. This interaction involved verifying an account number. The way the other group wrote their webservice is I am supposed to hit a specific url, retrieve a sessionid number and then use that number for subsequent requests. The problem I am having is that when I pass the sessionid it needs to be contained in { } brackets. for example: "http://server/acctverify/Verification.groovy;jsessionid=${123456789}"
The problem lies in when I pass the above URL it gets encoded to something like this: http://server/acctverify/Verification.groovy;jsessionid=$%7B123456789%7D with the {}'s replaced.
I don't understand why this is happening nor how to fix it.
Code I am running:
开发者_JAVA百科 Dim client As WebClient = New WebClient
Dim Sessionuri As Uri = New Uri(VerifyInit)
Dim sessionID As String = client.DownloadString(Sessionuri)
Dim FinalUri As Uri = New Uri(VerifyPost & "{" & sessionID & "}?acctnumber=")
Dim FinalResults As String = client.DownloadString(FinalUri)
MessageBox.Show(FinalResults)
Thanks in advance for any help.
There is a deprecated constructor for the Uri class which will prevent URIs from being encoded when the dontEscape parameter of the constructor is True.
Like this:
Dim client As WebClient = New WebClient
Dim Sessionuri As Uri = New Uri(VerifyInit)
Dim sessionID As String = client.DownloadString(Sessionuri)
Dim FinalUri As Uri = New Uri(VerifyPost & "{" & sessionID & "}?acctnumber=", true)
Dim FinalResults As String = client.DownloadString(FinalUri)
MessageBox.Show(FinalResults)
This constructor is deprecated for good reason: the URI you're trying to create is not a legal URI. The {
and }
characters must be encoded. But if you're using a non-compliant server that only accepts unencoded characters, the constructor above should work.
精彩评论