WebGet 不恰当地添加尾部斜杠

发布于 2024-10-08 02:09:42 字数 974 浏览 1 评论 0原文

我有一个休息客户端尝试调用 http://my-server/section1/section2?param1= foo

http://my-server/section1/section2?param1=foo http://my-server/sectionX/sectionY?param2=bar http://my-server/sectionA/sectionC?param3=kuku

注意查询参数键名称更改(param1、param2、param3...)

我实现的合约是

[WebGet(UriTemplate = "")]
        [OperationContract]
        Message MyMethod();

但是这将导致调用的实际 uri 为: http://my-server/section1/section2/?param1=foo

请注意在section2 和? 之间添加了一个尾部斜杠。

有人知道如何预防吗?

大卫·

PS 请注意 1)将最后一个段+参数作为MyMethod的参数(并使用UriTemplate =“/ {lastSegment}”)的技巧将导致问号(?)被解码... 这会破坏呼叫请求 2) 完全删除 UriTemplate 将导致方法名成为 uri 的一部分...

I have a rest client which tries to call http://my-server/section1/section2?param1=foo

http://my-server/section1/section2?param1=foo
http://my-server/sectionX/sectionY?param2=bar
http://my-server/sectionA/sectionC?param3=kuku

notice that the query parameters key name changes (param1, param2,param3...)

The contract I implemented is

[WebGet(UriTemplate = "")]
        [OperationContract]
        Message MyMethod();

However this will cause the actual uri called to be:
http://my-server/section1/section2/?param1=foo

Note that a trailing slash has been added between section2 and ?

Does someone know how to prevent it?

David

PS
pls note that
1) a the trick of taking the last segment+ the parameters as a parameter to MyMethod (and usage of UriTemplate="/{lastSegment}) will cause the question mark (?) to be decoded...
which will ruin the call request
2) removing the UriTemplate completely will cause the methodname to be part of the uri...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

我为君王 2024-10-15 02:09:42

您确实不应该在客户端上使用 WCF 合约来调用 REST 服务。只需使用 HTTPWebRequest 或 HttpClient 进行这些调用即可。

You really should not use WCF contracts on the client to make calls to REST services. Simply use HTTPWebRequest or HttpClient to make those calls.

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