在.NET URL编码正斜杠(/) [英] Url Encode Forward Slash (/) in .NET

查看:665
本文介绍了在.NET URL编码正斜杠(/)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能强迫或者乌里的HttpWebRequest 允许包含一个URI既 / %2F 像下面?

How can I force either Uri or HttpWebRequest to allow a uri containing both / and %2f like the following?

http://localhost:55672/api/exchanges/%2f/MyExchange






我想这...


I tried this...

WebRequest request = 
    HttpWebRequest.Create("http://localhost:55672/api/exchanges/%2f/MyExchange");



...这...

...and this...

Uri uri = new Uri("http://localhost:55672/api/exchanges/%2f/MyExchange", true);
WebRequest request = HttpWebRequest.Create(uri);



...这...

...and this...

UriBuilder builder = new UriBuilder();
builder.Port = 55672;
builder.Path = "api/exchanges/%2f/MyExchange";
WebRequest request = HttpWebRequest.Create(builder.Uri);



与所有这些不过, request.RequestUri 结束的http://本地主机:55672 / API /交流/// MyExchange request.GetResponse()产生404响应。

However with all of these, request.RequestUri ends up http://localhost:55672/api/exchanges///MyExchange and request.GetResponse() produces a 404 response.

FYI我试图使用的RabbitMQ的HTTP API并键入Chrome的地址产生预期的JSON结果。

FYI I'm trying to use RabbitMQ's HTTP API and typing the Url in Chrome produces the expected JSON result.

推荐答案

我们刚刚有同样的问题,并发现,如果你的目标.NET 4.0框架存在这个问题。它消失了,如果你针对.NET 4.5框架。所以,如果这是你的一个选择,切换你的目标框架,它应该解决您的问题。

We just had the same problem and discovered that this problem exists if you are targeting the .NET 4.0 framework. It goes away if you target the .NET 4.5 framework. So if that's an option for you, switch your target framework and it should resolve your issue.

这篇关于在.NET URL编码正斜杠(/)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆