vb.net的WebClient编码问题

发布于 2024-12-04 16:42:01 字数 880 浏览 1 评论 0原文

在我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如痴如狂 2024-12-11 16:42:01

Uri 类有一个已弃用的构造函数,它将阻止 URI 被当构造函数的 dontEscape 参数为 True 时进行编码。

像这样:

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) 

此构造函数已被弃用,原因很充分:您尝试创建的 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:

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文