【发布时间】:2009-03-24 20:42:19
【问题描述】:
我正在改造一个应用程序以使用 PHP HTTP 代理(用于缓存)而不是实际的 API 服务器,该应用程序当前将服务器 URI 和路径与代码结合起来:
methodUri = new Uri(apiUri, method.Path)
地点:
- apiUri = "http://api.eve-online.com/"(System.Uri 对象)
- method.Path = "/char/SkillIntraining.xml.aspx"(字符串)
上面语句的结果是
"http://api.eve-online.com/char/SkillIntraining.xml.aspx" (System.Uri Object)
要使用 PHP HTTP 代理,必须将请求更改如下
- apiUri = "http://www.r-s.co.uk/eproxy.php"(System.Uri 对象)
- method.Path = "/char/SkillIntraining.xml.aspx"(字符串)
我期待的输出是:
"http://www.r-s.co.uk/eproxy.php/char/SkillIntraining.xml.aspx" (System.Uri Object)
但是我得到的输出是:
"http://www.r-s.co.uk/char/SkillIntraining.xml.aspx" (System.Uri Object)
我知道这是构造函数 Uri(Uri, string) 的正确功能,我的问题是什么是更好的函数或构造函数来代替它来获得我期望的输出?我尝试删除 method.Path 中的前导“/”,将其从绝对路径转换为相对路径,但这没有帮助。
注意: 以下两种解决方案都可以工作,但是 System.UriBuilder 提供了一种更强大的机制来组合 URI 和路径,在我的例子中,对资源的更改比使用 System.Uri。如果我可以选择,我会将两个答案都标记为正确。
【问题讨论】:
标签: c# .net web-services