vb.net的WebClient编码问题
在我的 vb.net 应用程序中,我正在与另一个小组编写的 Web 服务进行交互。此交互涉及验证帐号。另一组编写 Web 服务的方式是我应该点击特定的 url,检索 sessionid 号码,然后使用该号码进行后续请求。我遇到的问题是,当我传递 sessionid 时,它需要包含在 { } 括号中。例如:“http://server/acctverify/Verification.groovy;jsessionid=${123456789}”
问题在于,当我传递上述 URL 时,它会被编码为如下内容: http://server/acctverify/Verification.groovy;jsessionid=$%7B123456789%7D 替换为 {}。
我不明白为什么会发生这种情况,也不明白如何解决它。
我正在运行的代码:
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)
提前感谢您的帮助。
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:
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Uri 类有一个已弃用的构造函数,它将阻止 URI 被当构造函数的 dontEscape 参数为 True 时进行编码。
像这样:
此构造函数已被弃用,原因很充分:您尝试创建的 URI 不是合法的 URI。必须对
{
和}
字符进行编码。但是,如果您使用的是仅接受未编码字符的不兼容服务器,则上面的构造函数应该可以工作。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:
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.